├── LICENSE ├── README.md ├── images ├── demo1.png ├── demo2.png ├── demo3.png └── demo4.png ├── scripts ├── .captcha.jpg ├── solution1.py └── solution2.py └── template ├── captcha.php ├── index.html ├── lab1.php ├── lab2.php └── monofont.ttf /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 D3Ext 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Captcha Bypassing Lab 2 | 3 | If you want to practise captcha bypassing, this is the right place! 4 | 5 | ## Introduction 6 | 7 | This repo contains a lab to practise captcha bypassing and a python script which is already able to "break" the captcha and get the numbers of it. The lab has 2 parts, one to simply parse the captcha and the other one to combine the captcha with a simple login form 8 | 9 | ## Requirements 10 | 11 | To use the python script you need to have install the python ***pytesseract*** package as well as the ***tesseract*** command. Both of them used to convert images to text: 12 | 13 | To launch the lab you just need a php server and in order to generate the captcha you need to have installed php-gd and to have it enabled on `/etc/php/php.ini` by uncommenting the line `extension=gd` 14 | 15 | ## Installation 16 | 17 | Clone the repo and set up a php server on the lab folder 18 | 19 | ```sh 20 | git clone https://github.com/D3Ext/Captcha-Bypassing-Lab 21 | cd Captcha-Bypassing-Lab/template 22 | php -S 0.0.0.0:80 23 | ``` 24 | 25 | ## Solution 26 | 27 | In order to solve both labs the project has, there actually are infinite solutions but feel free to check the python scripts on the `scripts/` folder, `solution1.py` for the first part and `solution2.py` for the second one 28 | 29 | ## Demo 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | ## References 40 | 41 | ``` 42 | https://www.anura.io/blog/captcha-and-recaptcha-how-fraudsters-bypass-it 43 | https://book.hacktricks.xyz/pentesting-web/captcha-bypass 44 | ``` 45 | 46 | ## License 47 | 48 | This project is under MIT license 49 | 50 | Copyright © 2024, *D3Ext* 51 | 52 | -------------------------------------------------------------------------------- /images/demo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D3Ext/Captcha-Bypassing-Lab/f169fd01a7453b4fdb93cb2ca316f2571bd58a86/images/demo1.png -------------------------------------------------------------------------------- /images/demo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D3Ext/Captcha-Bypassing-Lab/f169fd01a7453b4fdb93cb2ca316f2571bd58a86/images/demo2.png -------------------------------------------------------------------------------- /images/demo3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D3Ext/Captcha-Bypassing-Lab/f169fd01a7453b4fdb93cb2ca316f2571bd58a86/images/demo3.png -------------------------------------------------------------------------------- /images/demo4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D3Ext/Captcha-Bypassing-Lab/f169fd01a7453b4fdb93cb2ca316f2571bd58a86/images/demo4.png -------------------------------------------------------------------------------- /scripts/.captcha.jpg: -------------------------------------------------------------------------------- 1 | 404 Not Found 7 |

Not Found

The requested resource /lab1.phpcaptcha.php?rand=991113378 was not found on this server.

-------------------------------------------------------------------------------- /scripts/solution1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import requests, time, os, re, signal, pytesseract, colorama, sys 4 | from colorama import Fore 5 | from PIL import Image 6 | 7 | def def_handler(sig, frame): 8 | print("\n\n[!] Exiting...") 9 | sys.exit(1) 10 | 11 | def GetCaptcha(base_url): 12 | loop = 0 13 | while loop == 0: 14 | try: 15 | # Create a session for multiple requests 16 | s = requests.session() 17 | 18 | print(Fore.MAGENTA + "[*]" + Fore.WHITE + " Obtaining captcha image url...") 19 | response = s.get(base_url) # Send request 20 | captcha_expression = re.search(r'\d{5,10}', response.text) # Use regex to filter for captcha rand url number 21 | image_url = base_url.removesuffix("lab1.php") + "captcha.php?rand=" + captcha_expression.group(0) # Build captcha image url 22 | 23 | print(Fore.GREEN + "[+]" + Fore.WHITE + " Image url: " + image_url) 24 | captcha_image = s.get(image_url) # Send request to image 25 | 26 | # Save captcha image in a file 27 | f = open("captcha.jpg", "wb") 28 | f.write(captcha_image.content) 29 | f.close() 30 | time.sleep(0.2) 31 | 32 | print(Fore.MAGENTA + "[*]" + Fore.WHITE + " Converting captcha image to text...") 33 | # Use pytesseract to parse image 34 | captcha_value = pytesseract.image_to_string(Image.open('captcha.jpg')).strip() 35 | os.remove("captcha.jpg") 36 | 37 | print(Fore.GREEN + "[+]" + Fore.WHITE + " Captcha value: %s" % captcha_value) 38 | time.sleep(0.2) 39 | 40 | print(Fore.MAGENTA + "[*]" + Fore.WHITE + " Checking if captcha is valid...") 41 | post_data = { 42 | 'captcha': '%s' % (captcha_value), 43 | 'submit': 'Submit' 44 | } 45 | 46 | r2 = s.post(base_url, data=post_data) 47 | 48 | if "captcha code is correct" in r2.text: 49 | print(Fore.GREEN + "\n[+]" + Fore.WHITE + " Captcha entered succesfully") 50 | loop = 1 51 | else: 52 | print(Fore.RED + "\n[-]" + Fore.WHITE + " Captcha entered incorrectly\n") 53 | except Exception as e: 54 | print(e) 55 | sys.exit(1) 56 | 57 | if __name__ == '__main__': 58 | if len(sys.argv) >= 2: 59 | base_url = sys.argv[1] 60 | GetCaptcha(base_url) 61 | else: 62 | print("Usage: python3 solution1.py http://127.0.0.1/lab1.php") 63 | sys.exit(0) 64 | 65 | -------------------------------------------------------------------------------- /scripts/solution2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | #if __name__ == '__main__': 4 | 5 | -------------------------------------------------------------------------------- /template/captcha.php: -------------------------------------------------------------------------------- 1 | 0xFF & ($integar >> 0x10), 115 | "green" => 0xFF & ($integar >> 0x8), 116 | "blue" => 0xFF & $integar); 117 | } 118 | 119 | ?> 120 | -------------------------------------------------------------------------------- /template/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Button Redirect 7 | 40 | 41 | 42 | 43 |
Captcha Bypassing Lab
44 | 45 |
46 | Lab 1 47 | Lab 2 48 |
49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /template/lab1.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |

5 | 6 |

7 |

Can't read the image? Click 8 | here 9 | to refresh 10 |

11 | 12 | 13 | 14 | 15 |
16 | 17 | 28 | 29 | Submitted captcha code does not match!

"; 38 | } else { 39 | $status = "

40 | Submitted captcha code is correct.

"; 41 | } 42 | } 43 | 44 | echo $status; 45 | ?> 46 | 47 | -------------------------------------------------------------------------------- /template/lab2.php: -------------------------------------------------------------------------------- 1 | Submitted captcha code does not match!

"; 16 | } else { 17 | if ($_POST['username'] == $USER) { 18 | if ($_POST['password'] == $PASSWORD) { 19 | echo "

Access Granted

"; 20 | } else { 21 | echo "

Invalid Password

"; 22 | } 23 | } else { 24 | echo "

Invalid User

"; 25 | } 26 | 27 | // $status = "

Submitted captcha code is correct.

"; 28 | } 29 | } 30 | echo $status; 31 | ?> 32 | 33 |
34 | Username:
35 | Password:
36 | Enter Captcha:
37 | 38 |

39 | 40 |

41 |

Can't read the image? Click 42 | here 43 | to refresh 44 |

45 | 46 | 47 | 48 | 49 | 50 |
51 | 52 | 59 | 60 | -------------------------------------------------------------------------------- /template/monofont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D3Ext/Captcha-Bypassing-Lab/f169fd01a7453b4fdb93cb2ca316f2571bd58a86/template/monofont.ttf --------------------------------------------------------------------------------