Skip to content

Commit 4ba47df

Browse files
author
Ziconius
committed
RESTful changes:
- Email now has greater stability, docs updated in parallel. - Initial endpoint for implant interaction. - Updated vaules in restful API to be conistent between GET and POST
1 parent f8b0d80 commit 4ba47df

File tree

9 files changed

+48
-26
lines changed

9 files changed

+48
-26
lines changed

FudgeC2/Data/DatabaseCampaign.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,6 @@ def get_all_campaign_implant_templates_from_cid(self, cid):
143143
return False
144144
results = self.db_methods.__splice_implants_and_generated_implants__(implant)
145145
return results
146+
def get_campaign_id_from_implant_id(self, imaplant_id):
147+
campaign_id = self.Session.query(ImplantTemplate.cid).filter(ImplantTemplate.iid==GeneratedImplants.iid, GeneratedImplants.unique_implant_id == imaplant_id).one()
148+
return campaign_id[0]

FudgeC2/Data/DatabaseImplant.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def update_host_data(self, unique_implant_key, host_data):
312312

313313
def Get_CampaignImplantResponses(self, cid):
314314
# Used by web app
315+
# To be removed
315316
# -- TODO: Refactor
316317
a = self.Session.query(ImplantResponse).filter(ImplantResponse.cid == cid).all()
317318
return_list = []
@@ -326,3 +327,8 @@ def Get_CampaignImplantResponses(self, cid):
326327
a['title'] = b[0]
327328
return_list.append(a)
328329
return return_list
330+
331+
def get_implant_responses(self, implant_id):
332+
responses = self.Session.query(ImplantResponse).filter(ImplantResponse.uik == implant_id).all()
333+
processed_responses = self.db_methods._sqlalc_rows_to_list(responses)
334+
return processed_responses

FudgeC2/Data/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ImplantCommands(Base):
119119
class ImplantResponse(Base):
120120
__tablename__ = 'implant_response'
121121
log_id = Column(INTEGER(11), nullable=False, index=True, primary_key=True)
122-
cid = Column(INTEGER(11), nullable=False, index=True)
122+
cid = Column(INTEGER(11), nullable=False, index=True) # This can be removed as implant_id should be the only linking element
123123
uik = Column(INTEGER(11), nullable=False, index=True)
124124
log_entry = Column(String(255), nullable=False)
125125
time = Column(INTEGER(11), nullable=False, index=True)

FudgeC2/ServerApp/ImplantManager.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from FudgeC2.c2_server.resources.email import Email, EmailTest
3838
from FudgeC2.c2_server.resources.implants import Implants
3939
from FudgeC2.c2_server.resources.implants import ImplantDetails
40+
from FudgeC2.c2_server.resources.implants import ImplantResponses
4041

4142

4243
blueprint = Blueprint('api', __name__)
@@ -46,9 +47,10 @@
4647
api.add_resource(Users,'/api/v1/users/','/api/v1/users')
4748
api.add_resource(Email, '/api/v1/email')
4849
api.add_resource(EmailTest, '/api/v1/email/test')
49-
# In development
50-
api.add_resource(Implants, '/api/vi/implants')
51-
api.add_resource(ImplantDetails, '/api/vi/implants/<string:implant_id>')
50+
# In development these endpoints are not considered production ready.
51+
api.add_resource(Implants, '/api/v1/implants')
52+
api.add_resource(ImplantDetails, '/api/v1/implants/<string:implant_id>')
53+
api.add_resource(ImplantResponses, '/api/v1/implants/<string:implant_id>/responses')
5254

5355

5456
# -- Context Processors --#

FudgeC2/ServerApp/templates/settings/GlobalSettings.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ <h5 class="modal-title" id="FormModalTitle"></h5>
178178
event.preventDefault();
179179

180180
var myBody = {
181-
"server_host": document.getElementById('email_cfg_server').value,
182-
"server_port": document.getElementById('email_cfg_port').value,
183-
"server_email": document.getElementById('email_cfg_account').value,
184-
"server_password": document.getElementById('email_cfg_password').value,
185-
"server_from_addr": document.getElementById('email_cfg_from_addr').value,
181+
"host": document.getElementById('email_cfg_server').value,
182+
"port": document.getElementById('email_cfg_port').value,
183+
"smtp_account": document.getElementById('email_cfg_account').value,
184+
"password": document.getElementById('email_cfg_password').value,
185+
"from_address": document.getElementById('email_cfg_from_addr').value,
186186
"check_config": true
187187
}
188188

@@ -216,11 +216,11 @@ <h5 class="modal-title" id="FormModalTitle"></h5>
216216
event.preventDefault();
217217

218218
var myBody = {
219-
"server_host": document.getElementById('email_cfg_server').value,
220-
"server_port": document.getElementById('email_cfg_port').value,
221-
"server_email": document.getElementById('email_cfg_account').value,
222-
"server_password": document.getElementById('email_cfg_password').value,
223-
"server_from_addr": document.getElementById('email_cfg_from_addr').value
219+
"host": document.getElementById('email_cfg_server').value,
220+
"port": document.getElementById('email_cfg_port').value,
221+
"smtp_account": document.getElementById('email_cfg_account').value,
222+
"password": document.getElementById('email_cfg_password').value,
223+
"from_address": document.getElementById('email_cfg_from_addr').value
224224
}
225225

226226
const a = email_config_endpoint(myBody)

FudgeC2/c2_server/resources/email.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ def get(self, gid=None):
2222
return {"message":data}, 302
2323

2424
def post(self):
25-
rj = request.json
25+
rj = {}
26+
try:
27+
rj = request.json
28+
except:
29+
print(request.text)
30+
2631
# Validate the contents of this and send to the Meail class
27-
server_email = rj.get("server_email", None)
28-
server_password = rj.get("server_password", None)
29-
server_host = rj.get("server_host", None)
30-
server_port = rj.get("server_port", None)
31-
from_address = rj.get("server_from_addr", None)
32+
server_email = rj.get("smtp_account", None)
33+
server_password = rj.get("password", None)
34+
server_host = rj.get("host", None)
35+
server_port = rj.get("port", None)
36+
from_address = rj.get("from_address", None)
3237
check_config= rj.get("check_config", False)
33-
print(f"State:\n{server_host}\n{server_port}\n{server_email}\n{server_password}\n{from_address}\n{check_config}")
3438
state, msg = email_client.configure_email_client(server_host, server_port, server_email, server_password, from_address, check_config)
3539
if state:
3640
return {"result":msg}, 200

FudgeC2/c2_server/resources/implants.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Implants(Resource):
99
method_decorators = [login_required]
1010

1111
def get(self):
12+
1213
parser = reqparse.RequestParser()
1314
parser.add_argument('campaign_id', type=int, help='Campaign IDs are numeric.')
1415
args = parser.parse_args()
@@ -24,9 +25,10 @@ def get(self):
2425

2526
class ImplantDetails(Resource):
2627
method_decorators = [login_required]
27-
28+
# Return the configuration of an implant
2829
def get(self, implant_id):
2930
# Take UID and return info on it.
31+
3032
pass
3133
return {}
3234

@@ -38,5 +40,11 @@ def get(self):
3840

3941
class ImplantResponses(Resource):
4042
method_decorators = [login_required]
41-
def get(self):
42-
pass
43+
def get(self, implant_id):
44+
# get all implant responses (pagination will be implemented later
45+
response_list = []
46+
campaign_id = db.campaign.get_campaign_id_from_implant_id(implant_id)
47+
if db.campaign.Verify_UserCanAccessCampaign(current_user.user_email, campaign_id):
48+
response_list = db.implant.get_implant_responses(implant_id)
49+
50+
return {"data": response_list}

FudgeC2/email_client/email_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def decorate(self, *args, **kwargs):
4444
if self.enable is not False:
4545
func(self, *args, **kwargs)
4646
else:
47-
print("NOT CONFIGURED")
4847
return False
4948
return decorate
5049

FudgeC2/email_client/email_notifications.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ def send_email_new_user_account(self, name, email, password):
5252
Thank you,
5353
"""
5454
result = ec.send_email(email, email_text)
55-
return result
55+
return result

0 commit comments

Comments
 (0)