-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhacker.py
More file actions
181 lines (152 loc) · 6.4 KB
/
hacker.py
File metadata and controls
181 lines (152 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from typing import Any
from mcp.server.fastmcp import FastMCP
import os
import subprocess # Import the full subprocess module
import asyncio
import requests
import time
# Initialize FastMCP server
mcp = FastMCP("Hackermcp")
@mcp.tool()
def create_memory_for_your_self(what_to_add: str) -> str:
"""Create a memory for yourself.
Args:
what_to_add: what to add to the text file to store for your memory
"""
with open("memory.txt", "a") as f:
f.write(what_to_add + "\n")
return f"Created memory for yourself: {what_to_add}"
@mcp.tool()
def read_memory() -> str:
"""Read the memory.
"""
with open("memory.txt", "r") as f:
return f.read()
# @mcp.tool()
# async def tcpdump(command: str,timeout: int = 10) -> str:
# """Capture network traffic using tcpdump.
# Args:
# command: command to run like -i eth0 -w output.pcap and timeout is the time to wait for the command to finish no need to mention tcpdump it is already there
# """
# result = subprocess.run(f"sudo tcpdump {command}", shell=True, check=True, capture_output=True, text=True,timeout=timeout)
# return result.stdout
@mcp.tool()
async def get_public_ip() -> str:
"""Get your public IP address."""
response = requests.get("https://api.ipify.org?format=json")
return response.json()["ip"]
@mcp.tool()
async def mylocalip_with_ifconfig() -> str:
"""Get your local IP address with ifconfig."""
result = subprocess.run("ifconfig", shell=True, check=True, capture_output=True, text=True)
return result.stdout
@mcp.tool()
async def nmapscan(command: str) -> str:
"""Scan network using nmap with command
Args:
command: nmap command to run like -p as nmap is already there no need to mention nmap
"""
try:
result = subprocess.run(f"nmap {command}", shell=True, check=True, capture_output=True, text=True)
return result.stdout
except subprocess.CalledProcessError as e:
return f"Error executing nmap command: {e}\n{e.stderr}"
@mcp.tool()
async def create_tmux_session(session_name: str = "msf_session") -> str:
"""Create a new tmux session.
Args:
session_name: Name for the tmux session
"""
try:
# Check if session already exists
check_result = subprocess.run(f"tmux has-session -t {session_name}",
shell=True, capture_output=True, text=True)
if check_result.returncode == 0:
return f"Session '{session_name}' already exists"
# Create new detached session
result = subprocess.run(f"tmux new-session -d -s {session_name}",
shell=True, check=True, capture_output=True, text=True)
return f"Created tmux session: {session_name}"
except subprocess.CalledProcessError as e:
return f"Error creating tmux session: {e}\n{e.stderr}"
@mcp.tool()
async def list_tmux_sessions() -> str:
"""List all tmux sessions."""
try:
result = subprocess.run("tmux list-sessions",
shell=True, check=True, capture_output=True, text=True)
return result.stdout
except subprocess.CalledProcessError as e:
if e.returncode == 1:
return "No tmux sessions found"
return f"Error listing tmux sessions: {e}\n{e.stderr}"
@mcp.tool()
async def run_in_tmux(session_name: str, command: str) -> str:
"""Run a command in a tmux session.
Args:
session_name: Name of the tmux session
command: Command to run in the session
"""
try:
# Check if session exists
check_result = subprocess.run(f"tmux has-session -t {session_name}",
shell=True, capture_output=True)
if check_result.returncode != 0:
return f"Session '{session_name}' does not exist"
# Send command to session
result = subprocess.run(f"tmux send-keys -t {session_name} '{command}' C-m",
shell=True, check=True, capture_output=True, text=True)
return f"Command sent to session '{session_name}': {command}"
except subprocess.CalledProcessError as e:
return f"Error sending command to tmux session: {e}\n{e.stderr}"
@mcp.tool()
async def capture_tmux_output(session_name: str, wait_time: int = 2) -> str:
"""Capture the current output of a tmux session.
Args:
session_name: Name of the tmux session
wait_time: Time to wait before capturing output (seconds)
"""
try:
# Check if session exists
check_result = subprocess.run(f"tmux has-session -t {session_name}",
shell=True, capture_output=True)
if check_result.returncode != 0:
return f"Session '{session_name}' does not exist"
# Wait for output
time.sleep(wait_time)
# Capture pane content
result = subprocess.run(f"tmux capture-pane -p -t {session_name}",
shell=True, check=True, capture_output=True, text=True)
return result.stdout
except subprocess.CalledProcessError as e:
return f"Error capturing tmux output: {e}\n{e.stderr}"
@mcp.tool()
async def start_msfconsole(session_name: str = "msf_session") -> str:
"""Start msfconsole in a tmux session.
Args:
session_name: Name of the tmux session to use
"""
# First ensure the session exists
create_result = await create_tmux_session(session_name)
# Start msfconsole in the session
run_result = await run_in_tmux(session_name, "msfconsole")
# Wait for msfconsole to initialize
time.sleep(5)
# Get initial output
output = await capture_tmux_output(session_name)
return f"Started msfconsole in session '{session_name}'.\nInitial output:\n{output}"
@mcp.tool()
async def kill_tmux_session(session_name: str) -> str:
"""Kill a tmux session.
Args:
session_name: Name of the tmux session to kill
"""
try:
result = subprocess.run(f"tmux kill-session -t {session_name}",
shell=True, check=True, capture_output=True, text=True)
return f"Killed tmux session: {session_name}"
except subprocess.CalledProcessError as e:
return f"Error killing tmux session: {e}\n{e.stderr}"
if __name__ == "__main__":
# Initialize and run the server
mcp.run(transport='stdio')