Skip to content

Commit 6f1a2ba

Browse files
authored
Merge pull request #137 from ipa-lab/restructuring
Clean-Up dependencies
2 parents 9191f75 + 6ce5a7e commit 6f1a2ba

File tree

4 files changed

+48
-31
lines changed

4 files changed

+48
-31
lines changed

pyproject.toml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,13 @@ dependencies = [
3838
'pydantic == 2.8.2',
3939
'openai == 1.65.2',
4040
'BeautifulSoup4',
41-
'nltk',
4241
'fastapi == 0.114.0',
4342
'fastapi-utils == 0.7.0',
4443
'uvicorn[standard] == 0.30.6',
4544
'dataclasses_json == 0.6.7',
4645
'websockets == 13.1',
47-
'pandas',
4846
'faker',
4947
'fpdf',
50-
'langchain_core',
51-
'langchain_community',
52-
'langchain_chroma',
53-
'langchain_openai',
54-
'markdown',
55-
'chromadb',
5648
]
5749

5850
[project.urls]
@@ -71,17 +63,26 @@ where = ["src"]
7163
[tool.pytest.ini_options]
7264
pythonpath = "src"
7365
addopts = ["--import-mode=importlib"]
66+
7467
[project.optional-dependencies]
75-
testing = ['pytest', 'pytest-mock', 'pandas', 'faker', 'langchain_core']
68+
testing = [
69+
'pytest',
70+
'pytest-mock',
71+
'faker',
72+
'langchain_core'
73+
]
74+
7675
dev = [
7776
'ruff',
7877
]
79-
rag-usecase = [
80-
'langchain-community',
78+
79+
rag = [
80+
'langchain_core',
81+
'langchain-community',
82+
'langchain-chroma',
8183
'langchain-openai',
8284
'markdown',
8385
'chromadb',
84-
'langchain-chroma',
8586
]
8687

8788
[project.scripts]

src/hackingBuddyGPT/usecases/linux_privesc.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
from hackingBuddyGPT.usecases.usecase import use_case
1010
from hackingBuddyGPT.utils import llm_util
1111
from hackingBuddyGPT.utils.logging import log_conversation
12-
from hackingBuddyGPT.utils.rag import RagBackground
12+
from hackingBuddyGPT.utils.rag import has_langchain
1313
from hackingBuddyGPT.utils.connectors.ssh_connection import SSHConnection
1414
from hackingBuddyGPT.utils.shell_root_detection import got_root
1515

16+
if has_langchain():
17+
from hackingBuddyGPT.utils.rag import RagBackground
18+
1619
template_analyze = Template("""Your task is to analyze the result of an executed command to determina
1720
a way to escalate your privileges into a root shell. Describe your findings including all needed
1821
information while being as concise as possible.
@@ -132,6 +135,10 @@ def init(self):
132135
guidance = []
133136

134137
if self.rag_path != '':
138+
if not has_langchain():
139+
self.log.console.print("[red]RAG path provided but langchain is not installed. Please install langchain to use RAG functionality, e.g., through `pip install -e .\[rag]`.[/red]")
140+
raise ImportError("langchain is not installed")
141+
135142
self._enable_rag = True
136143
self._rag_data = RagBackground(self.rag_path, self.llm)
137144

@@ -254,4 +261,4 @@ def check_success(self, cmd:str, result:str) -> bool:
254261
ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
255262
last_line = result.split("\n")[-1] if result else ""
256263
last_line = ansi_escape.sub("", last_line)
257-
return got_root(self.conn.hostname, last_line)
264+
return got_root(self.conn.hostname, last_line)

src/hackingBuddyGPT/utils/prompt_generation/information/pentesting_information.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import base64
22
import copy
3+
import csv
34
import glob
45
import os
56
import random
67
import re
78
import secrets
89
from typing import List
910

10-
import pandas
11-
1211
from hackingBuddyGPT.utils.openapi.openapi_parser import OpenAPISpecificationParser
1312
from hackingBuddyGPT.utils.prompt_generation.information.prompt_information import (
1413
PromptPurpose,
@@ -43,10 +42,15 @@ def __init__(self, openapi_spec_parser: OpenAPISpecificationParser, config) -> N
4342
self.available_numbers = []
4443
self.config = config
4544
file = self.get_file(self.config.get("csv_file"))
46-
if file == "Not found":
47-
self.df = pandas.DataFrame()
48-
else:
49-
self.df = pandas.read_csv(file[0], names=["username", "password"])
45+
self._credentials = []
46+
if file != "Not found":
47+
with open(file[0]) as csvfile:
48+
reader = csv.reader(csvfile, delimiter=',')
49+
for row in reader:
50+
self._credentials.append({
51+
'username': row[0],
52+
'password': row[1]
53+
})
5054

5155
# Parse endpoints and their categorization from the given parser instance
5256
categorized_endpoints = openapi_spec_parser.classify_endpoints(self.config.get("name"))
@@ -1486,14 +1490,11 @@ def mechanic_report(self, endpoint, account, prompts):
14861490
return prompts
14871491

14881492
def random_common_users(self, endpoint, login_path, login_schema, prompts):
1489-
if len(self.df) >= 10:
1490-
random_entries = self.df.sample(n=10,
1491-
random_state=42) # Adjust random_state for different samples
1492-
else:
1493-
# Either raise an error, sample fewer, or handle gracefully
1494-
random_entries = self.df.sample(n=len(self.df)) if len(self.df) > 0 else pandas.DataFrame()
1493+
random_entries = random.sample(self._credentials)
1494+
if len(random_entries) >= 10:
1495+
random_entries = random_entries[:10]
14951496

1496-
for index, random_entry in random_entries.iterrows():
1497+
for index, random_entry in random_entries:
14971498
username = random_entry['username']
14981499
password = random_entry['password']
14991500
# Now you can print or use username and password as needed

src/hackingBuddyGPT/utils/rag.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
from langchain_community.document_loaders import DirectoryLoader, TextLoader
2-
from langchain_chroma import Chroma
3-
from langchain_openai import OpenAIEmbeddings
4-
from langchain_text_splitters import MarkdownTextSplitter
1+
try:
2+
from langchain_community.document_loaders import DirectoryLoader, TextLoader
3+
from langchain_chroma import Chroma
4+
from langchain_openai import OpenAIEmbeddings
5+
from langchain_text_splitters import MarkdownTextSplitter
6+
except ImportError:
7+
_has_langchain = False
8+
else:
9+
_has_langchain = True
10+
11+
def has_langchain():
12+
return _has_langchain
513

614
class RagBackground:
715

0 commit comments

Comments
 (0)