diff --git a/Dockerfile b/Dockerfile index 278c9a6..93d5423 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,17 @@ -FROM python:3.13.0rc2-bookworm +FROM python:3.11.10-bookworm WORKDIR /usr/src/app COPY ./requirements.txt . RUN apt update -RUN apt install nmap -y -RUN pip install --no-cache-dir -r requirements.txt -vvv +RUN apt install -y iputils-ping +RUN apt install -y dnsutils +RUN apt install -y nmap +RUN apt install -y python3 +RUN apt install -y python3-pip +RUN pip3 install discord +RUN pip3 install openai +RUN pip3 install aiohttp +RUN pip3 install requests CMD [ "python", "./garfbot.py" ] diff --git a/garfbot.py b/garfbot.py index cc46273..757d909 100644 --- a/garfbot.py +++ b/garfbot.py @@ -8,6 +8,7 @@ import aiohttp import asyncio import discord import requests +import ipaddress import subprocess from base64 import b64encode from openai import AsyncOpenAI @@ -49,6 +50,18 @@ intents.message_content = True garfbot = discord.Client(intents=intents) +# Network Utils Setup +def is_private(target): + try: + ip_obj = ipaddress.ip_address(target) + if ip_obj.is_private: + return True + except ValueError: + if "crate.lan" in target.lower(): + return True + return False + + # Kroger Setup client_id = config.CLIENT_ID client_secret = config.CLIENT_SECRET @@ -224,9 +237,49 @@ async def on_message(message): if message.content.lower().startswith("garfping "): try: query = message.content.split() + user = message.author.name + server = message.guild.name if message.guild else "Direct Message" target = query[-1] - result = subprocess.run(['ping', '-c', '1', target], capture_output=True, text=True) - await message.channel.send(f"`Ping result for {target}: {result.stdout}`") + print(f"Ping Request - User: {user}, Server: {server}, Target: {target}", flush=True) + if is_private(target): + rejection = await generate_chat_response("Hey Garfield, explain to me why I am dumb for trying to hack your private computer network.") + await message.channel.send(rejection) + else: + result = subprocess.run(['ping', '-c', '4', target], capture_output=True, text=True) + await message.channel.send(f"`Ping result for {target}: {result.stdout}`") + except Exception as e: + await message.channel.send(f"`GarfBot Error: {str(e)}`") + + if message.content.lower().startswith("garfdns "): + try: + query = message.content.split() + user = message.author.name + server = message.guild.name if message.guild else "Direct Message" + target = query[-1] + print(f"NSLookup Request - User: {user}, Server: {server}, Target: {target}", flush=True) + if is_private(target): + rejection = await generate_chat_response("Hey Garfield, explain to me why I am dumb for trying to hack your private computer network.") + await message.channel.send(rejection) + else: + result = subprocess.run(['nslookup', target], capture_output=True, text=True) + await message.channel.send(f"`NSLookup result for {target}: {result.stdout}`") + except Exception as e: + await message.channel.send(f"`GarfBot Error: {str(e)}`") + + if message.content.lower().startswith("garfhack "): + try: + query = message.content.split() + user = message.author.name + server = message.guild.name if message.guild else "Direct Message" + target = query[-1] + print(f"Nmap Request - User: {user}, Server: {server}, Target: {target}", flush=True) + if is_private(target): + rejection = await generate_chat_response("Hey Garfield, explain to me why I am dumb for trying to hack your private computer network.") + await message.channel.send(rejection) + else: + await message.channel.send(f"`Scanning {target}...`") + result = subprocess.run(['nmap', '-Pn', '-O', '-v', target], capture_output=True, text=True) + await message.channel.send(f"`Ping result for {target}: {result.stdout}`") except Exception as e: await message.channel.send(f"`GarfBot Error: {str(e)}`") diff --git a/garfbot.sh b/garfbot.sh new file mode 100644 index 0000000..7eaaf52 --- /dev/null +++ b/garfbot.sh @@ -0,0 +1 @@ +docker run -d --restart always -v $PWD:/usr/src/app --name garfbot garfbot \ No newline at end of file