Added python code to run sherlock as web api.

pull/2094/head
Herr Turing 3 months ago
parent e3a09f8bf1
commit 8b5b117e5f

@ -3,5 +3,6 @@ version: '2'
services:
sherlock:
build: .
image: sherlock
volumes:
- "./results:/opt/sherlock/results"

@ -0,0 +1,9 @@
FROM sherlock
RUN pip3 install fastapi[all]
COPY main.py /app/
WORKDIR /app/
ENTRYPOINT ["uvicorn", "main:app", "--host=0.0.0.0", "--port=8000", "--reload"]

@ -0,0 +1,45 @@
import subprocess
import sys
from typing import Annotated
from fastapi import FastAPI, Query
from fastapi.responses import StreamingResponse
app = FastAPI()
@app.get("/")
async def root(
usernames: Annotated[list[str] | None, Query()] = None,
f: Annotated[list[str] | None, Query()] = None,
):
command = ["python3", "/opt/sherlock/sherlock/sherlock.py"]
if usernames:
for name in usernames:
command.append(name)
if f:
for flag in f:
command.append("--"+flag)
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=sys.stderr)
response = []
for line in iter(process.stdout.readline, b''):
line = line.decode("utf-8").rstrip("\n").rstrip("\r")[4:]
if line == "":
continue
if line.startswith("Checking username"):
continue
if line.startswith("Search complete"):
continue
data = line.split(": ")
response.append(dict(name= data[0], link= data[1]))
return response

@ -0,0 +1,7 @@
services:
api:
build: ./api
volumes:
- ./api/main.py:/app/main.py
ports:
- 8000:8000
Loading…
Cancel
Save