# MD5 password ### Decription: This is an md5 password problem. The format of PHP's md5 function is given. Let's take a look and solve the problem ![](https://hackmd.io/_uploads/SyLz5ika2.png) Ta thử xem source code của nó nào ![](https://hackmd.io/_uploads/Bkf6qoJpn.png) Nó tạo cho ta một bảng admin_password sau đó thực hiện truy vấn ``` select * from admin_password where password= md5(params, true) ``` md5 hashes giá trị của biến ```$ps``` và lưu nó vào biến ```$row``` nếu tồn tại trong bảng admin_password - md5() function: md5 hashes the string entered as a parameter and returns it as a length of 32 bytes Hmm chúng ta cần tìm giá trị password bị hashes bởi md5 có ve khá là khoai :>. Tuy nhiên hãy nhìn vào cách md5() function được sử dụng giá trị ***second argument can be given optionally***, raw_input.... Really !!! ```The default (default value) of the raw_output option is False, and if it is set to True, a 32 bytes long Hex value is returned as a 16 bytes binary value``` Ta thử viết một chương trình đơn giản ``` import hashlib value = b"password" value_md5 = hashlib.md5(value) value_hex = value_md5.hexdigest() value_bin = value_md5.digest() print("md5_hash hex = ", value_hex) print("md5_hash binary = ", value_bin) ``` ![](https://hackmd.io/_uploads/HkiRk2kT3.png) Quay trở lại với câu truy vấn ban nãy nếu ra sao chúng ta có thể chèn 'or' vào bằng một cách nào đó lúc này nó sẽ trở thành ``` select * from admin_password where password = '' or ' ' ``` ***False or True*** return **True** và nó sẽ trở thành ```select * from admin_password where True ``` Vì chúng ta biết MD% hash sẽ chuyển giá trị truyền vào thành 16 bytes binary values sẽ ra sao nếu thôi chèn giá trị *129581926211651571912466741651878684928* Và boom having weird thing happen !!! ![](https://hackmd.io/_uploads/r1W8W2J63.png) Lưu nó và lấy flag :> ![](https://hackmd.io/_uploads/HkX0Zn163.png)