├── README.md └── old ├── README.md ├── main.py └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | 2 | ```py 3 | json_data = { 4 | "requests": [{ 5 | "image": { 6 | "content": "base64 encoded image" 7 | }, 8 | "features": [{"type": "TEXT_DETECTION"}] 9 | }] 10 | } 11 | 12 | req = requests.post( 13 | url = 'https://content-vision.googleapis.com/v1/images:annotate', 14 | headers = { 15 | 'x-origin': 'https://explorer.apis.google.com', 16 | }, 17 | params = { 18 | 'alt': 'json', 19 | 'key': 'AIzaSyAa8yy0GdcGPHdtD083HiGGx_S0vMPScDM', 20 | }, 21 | json = json_data 22 | ) 23 | 24 | print(req.json()) 25 | ``` 26 | -------------------------------------------------------------------------------- /old/README.md: -------------------------------------------------------------------------------- 1 |

2 | Zefoy Captcha Solver 👻 3 |

4 | 5 |

6 | Zefoy OCR bruteforce captcha solver using cv2, PIL and pytesseract aswell as the Zefoy API 7 |

8 | 9 |

10 | 11 | 12 | 13 |

14 | 15 |

16 | 17 | 18 | 19 | 20 |

21 | 22 |

23 | 🌌・Discord 24 | 📜・ChangeLog 25 |

26 | 27 |

28 | Zefoy Captcha Solver was made by 29 | 30 | Love ❌ code ✅ 31 | 32 |

33 | 34 | --- 35 | 36 | ## :fire: Features 37 | 38 | ✔ Solves the zefoy captcha under 20s 39 | 40 | --- 41 | 42 | ## 🚀・Zefoy Captcha Solver 43 | 44 | ```sh-session 45 | > Install python and pip 46 | > Download this repo or git-clone it 47 | > Install the requirements with: pip install -r requirements.txt 48 | > run main.py, you may aswell then add your code when the captcha gets solved 49 | ``` 50 | 51 | ## 🤝・Contributing 52 | 53 | - The solver is not accurate at all, if you wish you can optimize it and make a pull request 54 | 55 | ## 🎉・Upcoming/enhancements 56 | 57 | - Make it better faster 58 | 59 | 60 | ## 💭・ChangeLog 61 | 62 | ```diff 63 | v0.0.2 ⋮ 2022-06-10 64 | + better response when solved 65 | 66 | v0.0.1 ⋮ 2022-06-10 67 | + initial commit 68 | ``` 69 | 70 | ## x・Filter Example 71 | ```python 72 | import os, cv2, numpy, pytesseract, PIL, re, enchant 73 | from tkinter import W 74 | import scipy.ndimage as ndimage 75 | import matplotlib.pyplot as plt 76 | 77 | file = cv2.imread(f"./captcha.png") 78 | thresh, im_bw = cv2.threshold(file, 200, 260, cv2.THRESH_BINARY) 79 | _name = f'./enhanced.png' 80 | b = cv2.imwrite(_name, im_bw) 81 | def bbox(im): 82 | a = numpy.array(im)[:,:,:3] 83 | m = numpy.any(a != [255, 255, 255], axis=2) 84 | coords = numpy.argwhere(m) 85 | y0, x0, y1, x1 = *numpy.min(coords, axis=0), *numpy.max(coords, axis=0) 86 | return (x0, y0+1, x1-1, y1-1) 87 | 88 | im = PIL.Image.open(_name) 89 | im2 = im.crop(bbox(im)) 90 | im2.save(_name) 91 | 92 | 93 | image = PIL.Image.open(_name) 94 | inverted_image = PIL.ImageOps.invert(image) 95 | inverted_image.save(_name) 96 | 97 | im = PIL.Image.open(_name) 98 | im2 = im.crop(bbox(im)) 99 | im2.save(_name) 100 | 101 | basewidth = 700 102 | img = PIL.Image.open(_name) 103 | wpercent = (basewidth/float(img.size[0])) 104 | hsize = int((float(img.size[1])*float(wpercent))) 105 | img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS) 106 | img.save(_name) 107 | 108 | cv2.imwrite(_name, cv2.threshold(cv2.dilate(cv2.threshold(cv2.imread(_name), 115, 255, cv2.THRESH_BINARY_INV)[1], cv2.getStructuringElement(cv2.MORPH_RECT, (3,3)), iterations=1), 115, 255, cv2.THRESH_BINARY_INV)[1]) 109 | 110 | ocr = pytesseract.image_to_string(_name, lang='eng', config='--psm 6 --oem 3') 111 | captcha = str(ocr) 112 | 113 | if captcha != "" and not None or not None: 114 | _captcha = re.compile('[^a-zA-Z]').sub('', captcha).lower() 115 | print(_captcha) 116 | ``` 117 | 118 | ## x・Comparison 119 | #### Before 120 | ![captcha](https://user-images.githubusercontent.com/98614666/173166442-dab67c1b-6b90-49e3-a3df-85d69797c68b.png) 121 | #### After 122 | ![enhanced](https://user-images.githubusercontent.com/98614666/173166447-82fd2154-e98d-41dc-ac49-0b6b1105da8a.png) 123 | 124 | 125 | 126 |

127 | README.md inspired from Rdimo 128 |

129 | -------------------------------------------------------------------------------- /old/main.py: -------------------------------------------------------------------------------- 1 | import pytesseract, cv2, requests, os, random, threading, re, sys, time, enchant, shutil, numpy 2 | from PIL import Image 3 | 4 | pytesseract.pytesseract.tesseract_cmd = r"C:/Program Files (x86)/Tesseract-OCR/tesseract.exe" 5 | sys.setrecursionlimit(1500) 6 | 7 | class Solver: 8 | def __init__(self): 9 | self.config = '--psm 6 --oem 3' 10 | self.base_url = "https://zefoy.com/" 11 | 12 | self.start = time.time() 13 | self.reqs = 0 14 | 15 | threading.Thread(target=self.monitor).start() 16 | 17 | while True: 18 | self.solve() 19 | 20 | if threading.active_count() < 2 + 1: 21 | threading.Thread(target=self.solve).start() 22 | 23 | def monitor(self): 24 | while True: 25 | os.system(f'title Captcha Solver ^| Requests ~ {self.reqs} ^| Time Elapsed ~ {round(time.time() - self.start, 1)}s') 26 | time.sleep(0.5) 27 | 28 | 29 | def solve(self): 30 | try: 31 | sess = requests.Session() 32 | num = random.randint(1000, 9999) 33 | 34 | sessid = sess.get( 35 | self.base_url, 36 | headers={ 37 | "origin": "https://zefoy.com", 38 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36", 39 | "x-requested-with": "XMLHttpRequest" 40 | } 41 | ).cookies.values()[0] 42 | 43 | response = sess.get( 44 | self.base_url + "a1ef290e2636bf553f39817628b6ca49.php", 45 | headers={ 46 | "origin": "https://zefoy.com", 47 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36", 48 | "x-requested-with": "XMLHttpRequest", 49 | "cookie": f"PHPSESSID={sessid}", 50 | }, 51 | params={ 52 | "_CAPTCHA": "", 53 | "t": "0.23092200 1654778649" 54 | } 55 | ) 56 | 57 | with open(f"./captchas/captcha{num}.png", 'wb') as _: 58 | _.write(response.content) 59 | 60 | file = cv2.imread(f"./captchas/captcha{num}.png") 61 | os.remove(f"./captchas/captcha{num}.png") 62 | thresh, im_bw = cv2.threshold(file, 190, 260, cv2.THRESH_BINARY) 63 | _name = f'./captchas/enhanced{num}.png' 64 | b = cv2.imwrite(_name, im_bw) 65 | def bbox(im): 66 | a = numpy.array(im)[:,:,:3] 67 | m = numpy.any(a != [255, 255, 255], axis=2) 68 | coords = numpy.argwhere(m) 69 | y0, x0, y1, x1 = *numpy.min(coords, axis=0), *numpy.max(coords, axis=0) 70 | return (x0, y0, x1+1, y1+1) 71 | 72 | im = Image.open(_name) 73 | im2 = im.crop(bbox(im)) 74 | im2.save(_name) 75 | 76 | ocr = pytesseract.image_to_string(_name, config=self.config) 77 | captcha = str(ocr) 78 | 79 | if captcha != "" and not None or not None: 80 | _captcha = re.compile('[^a-zA-Z]').sub('', captcha).lower() 81 | 82 | d = enchant.Dict("en_US") 83 | if d.check(_captcha) == False: 84 | _captcha = d.suggest(_captcha)[0] 85 | 86 | if len(_captcha) > 2: 87 | 88 | print(_captcha) 89 | 90 | shutil.copy(f"./captchas/enhanced{num}.png", f"./solved/{_captcha}.png") 91 | 92 | _response = sess.post( 93 | "https://zefoy.com", 94 | data={ 95 | "captcha_secure": _captcha, 96 | "r75619cf53f5a5d7aa6af82edfec3bf0": "" 97 | }, 98 | headers={ 99 | "cookie": f"PHPSESSID={sessid}", 100 | "origin": "https://zefoy.com", 101 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36", 102 | "x-requested-with": "XMLHttpRequest" 103 | } 104 | ) 105 | 106 | if "c2VuZF9mb2xsb3dlcnNfdGlrdG9r" in _response.text: 107 | print(f"SOLVED | Time: {time.time() - self.start}s | Trials: {self.reqs} | Sessid: {sessid}") 108 | sys.exit('solved successfully') 109 | else: 110 | pass 111 | 112 | self.reqs += 1 113 | 114 | os.remove(f'./captchas/enhanced{num}.png') 115 | 116 | except Exception as e: 117 | try: 118 | os.remove(f'./captchas/enhanced{num}.png') 119 | os.remove(f"./captchas/captcha{num}.png") 120 | except: 121 | pass 122 | 123 | 124 | if __name__ == "__main__": 125 | os.system("cls" if os.name == 'nt' else 'clear') 126 | Solver() 127 | -------------------------------------------------------------------------------- /old/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy==1.22.3 2 | opencv-python==4.6.0.66 3 | pyenchant==3.2.2 4 | pytesseract==0.3.9 5 | requests==2.27.1 6 | PIL-Tools==1.1.0 7 | --------------------------------------------------------------------------------