Skip to content

Commit 591b21d

Browse files
merge branch (#49)
merge
2 parents c6e8908 + 0e00f6d commit 591b21d

File tree

22 files changed

+417
-97
lines changed

22 files changed

+417
-97
lines changed

LICENSE

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
This is free and unencumbered software released into the public domain.
1+
MIT License
22

3-
Anyone is free to copy, modify, publish, use, compile, sell, or
4-
distribute this software, either in source code form or as a compiled
5-
binary, for any purpose, commercial or non-commercial, and by any
6-
means.
3+
Copyright (c) 2025 DEFENSE INTELLIGENCE AGENCY • PROJECT RED SWORD
74

8-
In jurisdictions that recognize copyright laws, the author or authors
9-
of this software dedicate any and all copyright interest in the
10-
software to the public domain. We make this dedication for the benefit
11-
of the public at large and to the detriment of our heirs and
12-
successors. We intend this dedication to be an overt act of
13-
relinquishment in perpetuity of all present and future rights to this
14-
software under copyright law.
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
1511

16-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19-
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20-
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22-
OTHER DEALINGS IN THE SOFTWARE.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
2314

24-
For more information, please refer to <https://unlicense.org>
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

advanced-zero-click-deployment-interface/FlowSteering/ApplicationCode/LLaVaServer/LLaVaServer.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
SERVER_HOST = '0.0.0.0'
1010
SERVER_PORT = 1025
1111
saveMail_directory = "FlowSteering/ApplicationCode/LLaVaServer/EmailLLaVaMailDatabase"
12-
MODEL_NAME = "FlowSteering/llava/llava_weights/" # PATH to the LLaVA weights
12+
MODEL_NAME = "FlowSteering/llava/llava_weights/" # PATH to the LLaVa weights
1313
message_queue = Queue()
1414
# Server configuration
1515

@@ -33,7 +33,10 @@ def receive_complete_data(
3333
except socket.timeout as e:
3434
print('timeout')
3535
print(e)
36-
36+
pass
37+
except socket.error as e:
38+
print('socket error')
39+
print(e)
3740
pass
3841

3942
return received_data
@@ -70,9 +73,9 @@ def SendToLLaVa(data, client_socket, sender, recipient, subject, model, image_pr
7073
for part in msg.get_payload():
7174
if part.get_content_type() == "text/plain":
7275
body = part.get_payload()
73-
7476
else:
75-
print(msg.get_payload())
77+
body = msg.get_payload()
78+
7679
# print the subject
7780
for part in msg.walk():
7881
if part.get_content_maintype() == "multipart":
@@ -124,7 +127,11 @@ def SendToLLaVa(data, client_socket, sender, recipient, subject, model, image_pr
124127

125128
def start_server(): # This function is used to start the server and listen for incoming connections
126129
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
127-
server_socket.bind((SERVER_HOST, SERVER_PORT))
130+
try:
131+
server_socket.bind((SERVER_HOST, SERVER_PORT))
132+
except socket.error as e:
133+
print(f"Error binding server socket: {e}")
134+
return
128135
server_socket.listen(1000)
129136
model, image_processor, tokenizer, device = Run_LLaVa.Turn_On_LLaVa() # Turn on the LLaVa model and get the model, image processor, tokenizer and the device
130137

advanced-zero-click-deployment-interface/FlowSteering/ApplicationCode/LLaVaServer/Run_LLaVa.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ def load_image(image_file):
7777
response = requests.get(image_file)
7878
image = Image.open(BytesIO(response.content)).convert('RGB')
7979
else:
80-
image = Image.open(image_file).convert('RGB')
80+
try:
81+
image = Image.open(image_file).convert('RGB')
82+
except Exception as e:
83+
print(f"Error loading image: {e}")
84+
return None
8185
return image
8286

8387

@@ -169,6 +173,8 @@ def generate_stream(model, prompt, tokenizer, input_ids, images=None):
169173
def run_result(X, prompt, initial_query, query_list, model, tokenizer, unnorm, image_processor):
170174
device = 'cuda'
171175
X = load_image(X)
176+
if X is None:
177+
return ["Error loading image"]
172178

173179
print("Image: ")
174180
# load the image
@@ -234,8 +240,13 @@ def Turn_On_LLaVa(): # Load the LLaVa model
234240
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
235241
dtypePerDevice = torch.float16
236242

237-
model = LlavaLlamaForCausalLM.from_pretrained(model_name, low_cpu_mem_usage=True, torch_dtype=dtypePerDevice,
238-
use_cache=True)
243+
try:
244+
model = LlavaLlamaForCausalLM.from_pretrained(model_name, low_cpu_mem_usage=True, torch_dtype=dtypePerDevice,
245+
use_cache=True)
246+
except Exception as e:
247+
print(f"Error loading model: {e}")
248+
return None, None, None, None
249+
239250
model.to(device=device, dtype=dtypePerDevice)
240251
image_processor = CLIPImageProcessor.from_pretrained(model.config.mm_vision_tower)
241252

@@ -264,7 +275,11 @@ def Turn_On_LLaVa(): # Load the LLaVa model
264275
def load_param(MODEL_NAME, model, tokenizer, initial_query):
265276
model_name = os.path.expanduser(MODEL_NAME)
266277

267-
image_processor = CLIPImageProcessor.from_pretrained(model.config.mm_vision_tower)
278+
try:
279+
image_processor = CLIPImageProcessor.from_pretrained(model.config.mm_vision_tower)
280+
except Exception as e:
281+
print(f"Error loading image processor: {e}")
282+
return None, None, None, None, None, None, None, None, None
268283

269284
mm_use_im_start_end = getattr(model.config, "mm_use_im_start_end", False)
270285
tokenizer.add_tokens([DEFAULT_IMAGE_PATCH_TOKEN], special_tokens=True)

advanced-zero-click-deployment-interface/FlowSteering/ApplicationCode/README.md

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
In this directory, you will find the code for the GenAI EcoSystem. The GenAI EcoSystem consists of a collection of scripts designed to simulate an email system with multiple users and dedicated servers.
1010

11-
12-
13-
1411
The system consists of three main components: the Email Server, the LLaVa Server, and the End User Clients.
1512
* The Email Server is responsible for sending and receiving emails from the End User Clients.
1613
* The LLaVa Server is the GenAI service responsible for handling the emails that were sent to the End User Clients.
@@ -25,9 +22,6 @@ The system consists of three main components: the Email Server, the LLaVa Server
2522

2623
In our experiments, we utilized a single machine to run both the Email Server and the LLaVa Server. This machine was equipped with a single NVIDIA Quadro RTX 6000 24GB GPU. Additionally, we employed seven virtual machines to run the End User Clients.
2724

28-
29-
30-
3125
## Running the GenAI EcoSystem
3226

3327
### 1. Run the Email Server
@@ -37,7 +31,7 @@ file to set the server configuration.
3731
```python
3832
SERVER_HOST = '0.0.0.0' # Change this to the IP address of the machine where the Email Server will run
3933
SERVER_PORT = 1234 # Change this to the port where the Email Server will listen
40-
saveMail_directory = "FlowSteering/ApplicationCode/EmailServer/Database/EmailServerMailDatabase" # Change this to the directory where you want to save the emails inbox for each user
34+
saveMail_directory = "FlowSteering/ApplicationCode/EmailServer/EmailServerMailDatabase" # Change this to the directory where you want to save the emails inbox for each user
4135
message_queue = Queue()
4236
default_image = 'FlowSteering/assets/PerturbatedImages/DjiPerturbClassForward.png'
4337
```
@@ -59,9 +53,6 @@ def handle_messages():
5953
Save_Email_To_Recipient()
6054
```
6155

62-
63-
64-
6556
#### To run the Email Server execute the following command in the EmailServer directory
6657
```bash
6758
python3 EmailServer.py
@@ -92,9 +83,6 @@ def handle_messages():
9283
SendToLLaVa()
9384
```
9485

95-
96-
97-
9886
#### To run the LLaVa Server execute the following command in the LLaVaServer directory
9987
```bash
10088
python3 LLaVaServer.py
@@ -109,16 +97,12 @@ Since this script is designed to run on multiple machines, you don't need to edi
10997
You can find an example of the CSV file named: [EndUserBaseEmails.csv](../../FlowSteering/ApplicationCode/EndUserCode/EndUserClientBaseEmails/EndUserBaseEmails.csv).
11098
The function responsible for reading this CSV file is located in the [EndUserClient.py](../../FlowSteering/ApplicationCode/EndUserCode/EndUserClient.py) file under the respective function.
11199

112-
113100
```python
114101
def read_emails_from_file():
115102
```
116103

117-
118-
119104
The script for each End User Client runs in a loop, sending a request to the Email Server to check the inbox for new emails every 10-20 seconds.
120105

121-
122106
```python
123107
def main():
124108
while True:
@@ -129,9 +113,6 @@ def main():
129113
If there is a new email in the inbox, the Email server will send the email to the End User Client, and a pop-up window will appear with the email content.
130114
Next the End User Client will send the email to the LLaVa Server for classification, and the LLaVa Server will send the classification back to the End User Client.
131115

132-
133-
134-
135116
| Pop-up Window | Queries sent to LLaVa |
136117
|---------------------------------------------|-----------------------------------------------------|
137118
| ![Image 1 Description](../../Assets/DJISpam.png) | ![Image 2 Description](../../Assets/LLaVaQuery.png) |
@@ -140,9 +121,6 @@ Finally, the End User Client will act based on the classification returned by th
140121

141122
For our experiments, we implemented the action "Forward" and left the other actions as placeholders.
142123

143-
144-
145-
146124
```python
147125
if Classification == 'reply':
148126
print('Manual action is required for replying to this email, so it will be transferred to the Manual Folder.')
@@ -157,10 +135,8 @@ For our experiments, we implemented the action "Forward" and left the other acti
157135
elif Classification == 'spam':
158136
print('Moving the email to the Spam Folder')
159137
pass
160-
161138
```
162139

163-
164140
#### To run the End User Client execute the following command in the EndUserCode directory and replace the configurations of the server and the user with your own configurations
165141
```bash
166142
python3 EndUserClient.py --SERVER_EMAIL_HOST 111.88.88.33 --SERVER_EMAIL_PORT 1234 --SERVER_LLAVA_HOST 111.55.55.33 --SERVER_LLAVA_PORT 1025 --MYEMAIL [email protected] --saveMail_directory "FlowSteering/ApplicationCode/EndUserCode/EndUserPersonalEmailDir" --BaseEmails_directory "FlowSteering/ApplicationCode/EndUserCode/EndUserClientBaseEmails/EndUserBaseEmails.csv" --CycleNewEmails True --default_image "FlowSteering/assets/PerturbatedImages/DjiPerturbClassForward.png"
@@ -172,9 +148,6 @@ Navigate to the [EndUserCode directory](../../FlowSteering/ApplicationCode/EndUs
172148

173149
This code is a simplified version of the End User Client, used solely to send the initial malicious email to the End User Clients, as they are not composing new emails.
174150

175-
176-
177-
178151
Configure the following variables to send the email:
179152
``` python
180153
def main():
@@ -195,25 +168,28 @@ Next, the Attacker Client will send two identical emails to the Email Server, wi
195168
SERVER_EMAIL_PORT)
196169
```
197170

198-
199-
200-
201171
#### To run the Attacker Client execute the following command in the EndUserCode directory and replace the configurations of the server and the user with your own configurations
202172
```bash
203173
python3 AttackerClient.py --SERVER_EMAIL_HOST 111.88.88.33 --SERVER_EMAIL_PORT 1234 --SERVER_LLAVA_HOST 111.55.55.33 --SERVER_LLAVA_PORT 1025 --MYEMAIL [email protected]
204174
```
205175

206-
207176
## Conclusion
208177

209178
In our experiments, we developed a basic GenAI email application consisting of several components. You are welcome to modify any part of the system and tailor it to your own requirements and preferences.
210179

180+
## Recent Changes and Additions
211181

182+
We have recently made several updates and additions to the codebase to enhance the functionality and performance of the GenAI EcoSystem. These changes include:
212183

184+
1. **Improved Network Handling**: Enhanced the network handling capabilities to address issues related to image transmission over sockets, especially when using virtual machines. A default image is now loaded when an image fails to send correctly due to network issues.
213185

186+
2. **Optimized Email Server**: Refined the Email Server's handling of incoming connections and email storage. The server now creates a directory to save the email inbox for each user, ensuring better organization and retrieval of emails.
214187

188+
3. **Enhanced LLaVa Server**: Updated the LLaVa Server to process incoming emails more efficiently using the LLaVa model. The server now listens for incoming connections, processes emails, and sends responses back to the End User Clients seamlessly.
215189

190+
4. **End User Client Improvements**: Improved the End User Client script to run in a loop, checking the inbox for new emails every 10-20 seconds. The script now handles email classification and actions based on the classification returned by the LLaVa Server.
216191

192+
5. **Attacker Client Simplification**: Simplified the Attacker Client script to send the initial malicious email to the End User Clients. The script now sends two identical emails to the Email Server, targeting specific recipients.
217193

218-
194+
These updates aim to provide a more robust and efficient GenAI EcoSystem, ensuring smooth communication and interaction between the various components.
219195

advanced-zero-click-deployment-interface/FlowSteering/llava/llava.egg-info/requires.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
einops
22
fastapi
3-
gradio==5.5.0
3+
gradio==5.11.0
44
markdown2[all]
55
numpy
66
requests
@@ -12,7 +12,7 @@ uvicorn
1212
wandb
1313
shortuuid
1414
httpx==0.24.0
15-
deepspeed==0.9.5
15+
deepspeed==0.15.1
1616
peft==0.4.0
1717
transformers==4.38.0
1818
accelerate==0.21.0

advanced-zero-click-deployment-interface/FlowSteering/llava/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ classifiers = [
1313
"License :: OSI Approved :: Apache Software License",
1414
]
1515
dependencies = [
16-
"einops", "fastapi", "gradio==5.5.0", "markdown2[all]", "numpy",
16+
"einops", "fastapi", "gradio==5.11.0", "markdown2[all]", "numpy",
1717
"requests", "sentencepiece", "tokenizers>=0.12.1",
1818
"torch", "torchvision", "uvicorn", "wandb",
1919
"shortuuid", "httpx==0.24.0",
20-
"deepspeed==0.9.5",
20+
"deepspeed==0.15.1",
2121
"peft==0.4.0",
2222
"transformers==4.38.0",
2323
"accelerate==0.21.0",

advanced-zero-click-deployment-interface/FlowSteering/llava/serve/gateway/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ sudo nginx -t # check `/etc/nginx/nginx.conf`
5555
sudo systemctl reload nginx # restart Nginx service to load the new config
5656
sudo systemctl status nginx # check the status of the Nginx service. It should be active (running).
5757
```
58+
59+
## Recent Changes and Additions
60+
61+
We have recently made several updates and additions to the codebase to enhance the functionality and performance of the Nginx gateway. These changes include:
62+
63+
1. **Improved Security Features**: Enhanced the security features of the Nginx gateway to provide better protection for Gradio servers. This includes additional firewall rules and connection limits.
64+
65+
2. **Optimized Load Balancing**: Refined the load balancing capabilities of the Nginx gateway to ensure efficient distribution of traffic across multiple Gradio servers.
66+
67+
3. **Dynamic Server Management**: Updated the Nginx configuration to support dynamic mounting and unmounting of Gradio servers, allowing for more flexible server management.
68+
69+
4. **Simplified Deployment Process**: Streamlined the deployment process for the Nginx gateway, making it easier to set up and configure on various Linux distributions.
70+
71+
These updates aim to provide a more robust and efficient Nginx gateway, ensuring smooth communication and interaction between the various components of the system.

c2_dashboard.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,35 @@ class C2Dashboard:
44
def render(self):
55
return pn.Column(
66
"### Command and Control Dashboard",
7-
pn.pane.Markdown("Welcome to the C2 Dashboard. Here you can manage and monitor your operations.")
7+
pn.pane.Markdown("Welcome to the C2 Dashboard. Here you can manage and monitor your operations."),
8+
pn.pane.Markdown("#### Detailed Metrics and Insights"),
9+
pn.widgets.DataFrame(name="Metrics Data"),
10+
pn.pane.Markdown("#### Visualizations"),
11+
pn.widgets.DataFrame(name="Assets Data"),
12+
pn.pane.Markdown("#### Message Boards"),
13+
pn.widgets.DataFrame(name="Message Board Data"),
14+
pn.pane.Markdown("#### Announcements"),
15+
pn.widgets.DataFrame(name="Announcements Data"),
16+
pn.pane.Markdown("#### Latest News on Exploits"),
17+
pn.widgets.DataFrame(name="Latest News Data"),
18+
pn.pane.Markdown("#### AI Interface"),
19+
pn.widgets.DataFrame(name="AI Interface Data"),
20+
pn.pane.Markdown("#### System Connections"),
21+
pn.widgets.DataFrame(name="System Connections Data"),
22+
pn.pane.Markdown("#### Logs"),
23+
pn.widgets.DataFrame(name="Logs Data"),
24+
pn.pane.Markdown("#### System Status"),
25+
pn.widgets.DataFrame(name="System Status Data"),
26+
pn.pane.Markdown("#### System Settings"),
27+
pn.widgets.DataFrame(name="System Settings Data"),
28+
pn.pane.Markdown("#### Attack Simulations"),
29+
pn.widgets.DataFrame(name="Attack Simulations Data"),
30+
pn.pane.Markdown("#### Fuzzing"),
31+
pn.widgets.DataFrame(name="Fuzzing Data"),
32+
pn.pane.Markdown("#### Asset Control"),
33+
pn.widgets.DataFrame(name="Asset Control Data"),
34+
pn.pane.Markdown("#### Reverse Shell Settings"),
35+
pn.widgets.DataFrame(name="Reverse Shell Settings Data"),
36+
pn.pane.Markdown("#### Advanced Connection Methods"),
37+
pn.widgets.DataFrame(name="Advanced Connection Methods Data")
838
)

core/email_server/EmailServer.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ def Save_Email_To_Recipient(client_socket, data, msg, requests, subject, sender,
7272

7373
msg = email.message_from_bytes(data)
7474

75-
if msg.is_multipart():
76-
for part in msg.get_payload():
77-
if part.get_content_type() == "text/plain":
78-
body = part.get_payload()
79-
80-
else:
81-
print(msg.get_payload())
75+
try:
76+
if msg.is_multipart():
77+
for part in msg.get_payload():
78+
if part.get_content_type() == "text/plain":
79+
body = part.get_payload()
80+
else:
81+
body = msg.get_payload()
82+
except Exception as e:
83+
print(f"Error processing email message: {e}")
84+
client_socket.sendall("Error processing email message".encode('utf-8'))
85+
return
8286

8387
for part in msg.walk():
8488
if part.get_content_maintype() == "multipart":

core/integrations/email_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ def get_email_body(self, email_message) -> str:
7878
return email_message.get_payload(decode=True).decode()
7979
except Exception as e:
8080
self.logger.error(f"Error extracting email body: {e}")
81-
return ""
81+
return ""

0 commit comments

Comments
 (0)