-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathindex.js
2106 lines (2041 loc) · 55.9 KB
/
index.js
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var fs = require("fs")
var stream = require("stream")
const nodemailer = require("nodemailer")
const SMTPServer = require("smtp-server").SMTPServer
const dateFormat = require("dateformat")
const bunyan = require("bunyan");
const fastify = require('fastify')({
logger: true,
bodyLimit: 19922944
})
const got = require('got')
fastify.register(require('fastify-cookie'))
fastify.register(require('fastify-socket.io'), {})
const EventEmitter = require('events')
class GlobalEmitter extends EventEmitter {}
const globalEmitter = new GlobalEmitter()
async function sendMail(mail_object, io) {
return new Promise(function(resolve, reject) {
//add our own custom stream to send back to the client over websockets for debugging
var ioStream = new stream.Writable()
ioStream._write = function(chunk, encoding, done) {
try {
output = JSON.parse(chunk.toString()).msg;
//try to avoid mail content in the log feed. SMTP command output usually is not multi-lined
if (output.match(/\n/) == null) {
io.emit("smtp_command", {
campaign: mail_object.campaign,
data: output
})
}
} catch (err) {
io.emit("smtp_command", {
campaign: mail_object.campaign,
data: chunk.toString()
})
}
done()
}
let logger = bunyan.createLogger({
name: "nodemailer"
})
logger.level("debug");
logger.addStream({
name: "ioStream",
stream: ioStream,
level: "debug"
})
transport_settings = {
host: mail_object.supplied_mail_server,
name: mail_object.supplied_smtp_from.split("@")[1],
port: 25,
secure: false,
tls: {rejectUnauthorized: false},
logger,
debug: true
}
//Check to use supplied creds without the use of secure mail for sending through a relay
if (mail_object.supplied_username !== '' && mail_object.secure_mail == false){
transport_settings.auth = {
user: mail_object.supplied_username,
pass: mail_object.supplied_password
}
}
if (mail_object.dkim == true) {
transport_settings.dkim = {
domainName: mail_object.supplied_smtp_from.split("@")[1],
keySelector: "default",
privateKey: fs.readFileSync("./setup/dkim_private.pem", "utf8")
}
}
if (mail_object.secure_mail) {
transport_settings.port = 465
transport_settings.secure = true
transport_settings.auth = {
user: mail_object.supplied_username,
pass: mail_object.supplied_password
}
}
transport = new nodemailer.createTransport(transport_settings)
console.log(logger);
//make the necessary substitutions before sending
var now = new Date().toLocaleString("en-US", {timeZone: config.timezone})
timestamp = dateFormat(now, "ddd, dd mmm yyyy HH:MM:ss o");
let concat = mail_object.supplied_link.includes('?')?'&':'?'
let phishing_link =
mail_object.supplied_link +
concat +
mail_object.supplied_id_param +
"=" +
mail_object.target_id
let local_copy = mail_object.mail_data
local_copy = local_copy.replace(/DateTimeStamp/, timestamp)
local_copy = local_copy.replace(
/SuppliedToAddress/gm,
mail_object.supplied_mail_to
);
local_copy = local_copy.replace(/SuppliedPhishingLink/gm, phishing_link)
local_copy = local_copy.replace(
/SuppliedFirstName/gm,
mail_object.supplied_first_name
);
local_copy = local_copy.replace(
/SuppliedLastName/gm,
mail_object.supplied_last_name
);
local_copy = local_copy.replace(
/SuppliedPosition/gm,
mail_object.supplied_position
);
local_copy = local_copy.replace(
/SuppliedCustomReplacement/gm,
mail_object.supplied_custom_replacement
);
let attachment = ""
for (i = 0; i < phishing_link.length; i++) {
hex = phishing_link.charCodeAt(i).toString(16)
attachment += "\\x" + ("0" + hex).slice(-2)
}
//make the message content one single raw attachment like https://nodemailer.com/message/custom-source/
let message = {
envelope: {
from: mail_object.supplied_smtp_from,
to: [mail_object.supplied_mail_to]
},
raw: local_copy
}
transport.sendMail(message, function(err, info) {
if (err) {
console.log(err);
//just try to keep going anyway
createEvent(
{
//450 & 451 is greylist or rate limit
campaign: mail_object.campaign,
event_ip: "localhost",
target: mail_object.target_id,
event_type: "ERROR",
event_data: err.toString()
},
io
)
try {
got(
`https://api.telegram.org/` +
`${config.signal_bot.bot_id}` +
`/sendMessage?chat_id=` +
`${config.signal_bot.chat_id}` +
`&text=%22` +
`${mail_object.campaign}` +
`:ERROR:` +
`${err}` +
`%22`
);
} catch (err) {
console.log("Error sending Signal Message: " + err)
}
resolve(err);
//reject(err)
}
console.log(info);
var stmt = db.prepare(
`UPDATE targets
SET (phished) = 1
WHERE target_id = $target_id`
);
stmt.run({
"target_id": mail_object.target_id
})
resolve(info)
})
})
}
async function sendCampaign(campaign, io){
let target_query = db.prepare(`
SELECT * FROM targets WHERE campaign=$campaign
AND phished=0
`)
let target = target_query.get({campaign: campaign.name})
console.log(target)
if(target == undefined){
console.log(`stopping campaign: ${campaign.name} - No more targets`)
let set_end = db.prepare(`
UPDATE campaigns SET (end_timestamp, is_sending) = ($end_time, 0) WHERE name = $campaign
`)
let end_time = new Date().getTime()
set_end.run({end_time: end_time, campaign: campaign.name})
globalEmitter.emit(`stopCampaign-${campaign.name}`)
return
}else{
email = {}
email.target_id = target.target_id
email.supplied_mail_to = target.address
email.supplied_first_name = target.first_name
email.supplied_last_name = target.last_name
email.supplied_position = target.position
email.supplied_custom_replacement = target.custom
email.campaign = campaign.name
email.mail_data = campaign.email
email.supplied_link = campaign.phishing_link
email.supplied_id_param = campaign.id_parameter
email.supplied_smtp_from = campaign.smtp_from
email.supplied_mail_server = campaign.mail_server
email.supplied_username = campaign.username
email.supplied_password = campaign.password
if (campaign.secure == 1) {
email.secure_mail = true
} else {
email.secure_mail = false
}
if (campaign.dkim == 1) {
email.dkim = true
} else {
email.dkim = false
}
sendMail(email, io)
createEvent(
{
campaign: target.campaign,
event_ip: "localhost",
target: String(target.target_id),
event_type: "EMAIL_SENT",
event_data: target.address
},
io
)
}
}
async function captureMail(io) {
return new Promise(function(resolve, reject) {
server = new SMTPServer({
disabledCommands: ["STARTTLS", "AUTH"],
logger: true,
//socketTimeout: 3000,
secure: false //,
//key: fs.readFileSync("private.key"),
//cert: fs.readFileSync("server.crt")
})
//server.listen(465);
server.onData = function(stream, session, callback) {
stream.pipe(process.stdout); // print message to console
stream.on("data", function(data) {
io.emit("email_content", data)
})
stream.on("end", () => {
io.emit("capture_complete", {})
callback(null, "Message queued as pwnage")
stream.destroy()
server.close()
resolve;
})
}
server.onConnect = function(session, callback) {
console.log(session)
return callback()
}
server.listen(25)
})
}
// Import Swagger Options
const swagger = require('./config/swagger')
// Register Swagger
//fastify.register(require('fastify-swagger'), swagger.options)
//New Open API Standard
fastify.register(require('fastify-oas'), swagger.options)
config = JSON.parse(fs.readFileSync("./config.json"));
set_admin = config.set_admin.switch;
//database setup
const Database = require('better-sqlite3')
const { resolve } = require("path")
const db = new Database('./db/aquarium.db', { verbose: console.log })
let template_setup = db.prepare(`
CREATE TABLE IF NOT EXISTS templates (
name TEXT PRIMARY KEY,
email TEXT
)
`)
template_setup.run()
let campaign_setup = db.prepare(`
CREATE TABLE IF NOT EXISTS campaigns (
name TEXT,
email TEXT,
mail_server TEXT,
smtp_from TEXT,
phishing_link TEXT,
id_parameter TEXT,
delay INTEGER,
secure INTEGER,
username TEXT,
password TEXT,
dkim INTEGER,
scheduled_start INTEGER,
start_timestamp INTEGER,
end_timestamp INTEGER,
is_sending INTEGER,
market_id INTEGER
)
`)
campaign_setup.run()
let target_setup = db.prepare(`
CREATE TABLE IF NOT EXISTS targets (
target_id TEXT,
address TEXT,
campaign TEXT,
first_name TEXT,
last_name TEXT,
position TEXT,
custom TEXT,
phished INTEGER
)
`)
target_setup.run()
let event_setup = db.prepare(`
CREATE TABLE IF NOT EXISTS events (
event_timestamp INTEGER,
event_ip TEXT,
campaign TEXT,
target TEXT,
event_type TEXT,
event_data TEXT,
ignore INTEGER
)
`)
event_setup.run()
async function createEvent(new_event, io) {
console.log(new_event)
new_event.event_timestamp = new Date().getTime()
var event = db.prepare(`
INSERT INTO events VALUES (
$timestamp,
$ip,
$campaign,
$target,
$type,
$data,
$ignore
)`
)
event.run(
{
"timestamp": new_event.event_timestamp,
"ip": new_event.event_ip,
"campaign": new_event.campaign,
"target": new_event.target,
"type": new_event.event_type,
"data": new_event.event_data,
"ignore": 0
}
)
io.emit("new_event", new_event)
}
//make sure we are authorized
fastify.addHook('preHandler', (req, reply, done) => {
if(req.url.includes('documentation')){
done()
}else if((req.url.includes(config.set_admin.search_string) && set_admin)){
reply.header(
"set-cookie",
config.admin_cookie.cookie_name +
"=" +
config.admin_cookie.cookie_value +
";secure;httponly;max-age=31536000"
);
reply.redirect('/admin')
set_admin = false;
config.set_admin.switch = false;
fs.writeFileSync("./config.json", JSON.stringify(config, null, 4));
}else{
const admin_cookie = req.cookies['admin_cookie']
if(admin_cookie == config.admin_cookie.cookie_value){
done()
}else{
reply.code(401).send('Not Authorized')
done()
}
}
})
//favicon
fastify.route({
method: ['GET'],
url: '/favicon.ico',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/misc/favicon.ico")
reply.type('image/x-icon').send(stream)
}
})
//basic homepage. You can mod it to look like a normal server of your choosing
fastify.route({
method: ['GET'],
url: '/',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/pages/homepage.html")
reply.type('text/html').send(stream)
}
})
//static .js files
fastify.route({
method: ['GET'],
url: '/static/js/*',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/js/" + req.params['*'])
reply.type('text/javascript').send(stream)
}
})
//static .css files
fastify.route({
method: ['GET'],
url: '/static/css/*',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/styles/" + req.params['*'])
reply.type('text/css').send(stream)
}
})
//static admin homepage
fastify.route({
method: ['GET'],
url: '/admin',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/pages/admin.html")
reply.type('text/html').send(stream)
}
})
//static create campaign html
fastify.route({
method: ['GET'],
url: '/create_campaign',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/pages/create_campaign.html")
reply.type('text/html').send(stream)
}
})
//static edit campaign html
fastify.route({
method: ['GET'],
url: '/edit_campaign',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/pages/edit_campaign.html")
reply.type('text/html').send(stream)
}
})
//static view campaign html
fastify.route({
method: ['GET'],
url: '/track_campaign',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/pages/track_campaign.html")
reply.type('text/html').send(stream)
}
})
//static view targets for a campaign html
fastify.route({
method: ['GET'],
url: '/edit_targets',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/pages/edit_targets.html")
reply.type('text/html').send(stream)
}
})
//static view target html
fastify.route({
method: ['GET'],
url: '/view_target',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/pages/view_target.html")
reply.type('text/html').send(stream)
}
})
//static search events html
fastify.route({
method: ['GET'],
url: '/search_events',
handler: async function (req, reply) {
let stream = fs.createReadStream(__dirname + "/resources/pages/search_events.html")
reply.type('text/html').send(stream)
}
})
fastify.route({
method: ['GET'],
url: '/list_templates',
schema: {
security: [{cookieAuth: []}],
description: 'Get a list of local templates',
tags: ['Template'],
summary: 'get a list of template names',
response: {
200: {
description: 'Successful response',
type: 'array'
}
}
},
handler: async function (req, reply) {
let templates = db.prepare(`SELECT name FROM templates`).pluck()
reply.type('application/json').send(templates.all())
}
})
fastify.route({
method: ['GET'],
url: '/get_template',
schema: {
security: [{cookieAuth: []}],
description: 'Get a full local template',
tags: ['Template'],
summary: 'get a local template by name',
querystring: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'template name',
}
}
},
response: {
200: {
description: 'Successful response',
type: 'object',
properties: {
name: {
type: 'string'
},
email: {
type: 'string'
}
}
}
}
},
handler: async function (req, reply) {
let template_query = db.prepare(`
SELECT * FROM templates
WHERE name = $name
`)
let template_name = req.query['name']
let template = template_query.get({"name": template_name})
console.log(template)
reply.type('application/json').send(template)
}
})
fastify.route({
method: ['GET'],
url: '/list_campaigns',
schema: {
security: [{cookieAuth: []}],
description: 'Get a list of campaigns',
tags: ['Campaign'],
summary: 'get a list of campaigns',
response: {
200: {
description: 'Successful response',
type: 'array'
}
}
},
handler: async function (req, reply) {
let campaigns = db.prepare(`
SELECT
name,
mail_server,
smtp_from,
phishing_link,
id_parameter,
delay,
scheduled_start,
start_timestamp,
end_timestamp,
market_id,
is_sending
FROM campaigns
`)
reply.type('application/json').send(campaigns.all())
}
})
fastify.route({
method: ['POST'],
url: '/send_test_email',
schema:{
security: [{cookieAuth: []}],
description: 'Test a template or campaign email',
tags: ['Template','Campaign'],
summary: 'test a phishing email',
body: {
type: 'object',
properties: {
campaign: {
type: 'string',
default: 'test',
description: 'campaign name'
},
dkim: {
type: 'boolean',
default: false,
description: 'should we DKIM sign the message'
},
mail_data: {
type: 'string',
description: 'raw email message'
},
target_id: {
type: 'string',
default: 'test',
description: 'unique ID of the target user'
},
secure_mail: {
type: 'boolean',
default: false,
description: 'Should we use TLS for this message'
},
supplied_custom_replacement: {
type: 'string',
description: 'custom placeholder for per-target replacements'
},
supplied_delay: {
type: 'string',
default: "30",
description: 'delay between emails'
},
supplied_first_name: {
type: 'string',
description: 'substitution placeholder for target first names'
},
supplied_from_address:{
type: 'string',
description: 'email FROM address'
},
supplied_from_title:{
type: 'string',
description: 'email alias name'
},
supplied_id_param:{
type: 'string',
description: 'tracking ID GET param name for the target'
},
supplied_last_name: {
type: 'string',
description: 'substitution placeholdder for the target first name'
},
supplied_link: {
type: 'string',
description: 'base link URL for the phishing link'
},
supplied_mail_server: {
type: 'string',
description: 'mail server to send the test to'
},
supplied_mail_to:{
type: 'string',
description: 'target email address'
},
supplied_password:{
type: 'string',
description: 'password for authenticated SMTP relay'
},
supplied_position:{
type: 'string',
description: 'substitution placeholder for the target position'
},
supplied_smtp_from: {
type: 'string',
description: 'SMTP mail from: field'
},
supplied_username: {
type: 'string',
description: 'username for authenticated SMTP relay'
}
}
},
response: {
200: {
description: 'Successful response',
type: 'string'
}
}
},
handler: async function (req, reply) {
console.log(":sending test email: \n")
let email = req.body
sendMail(email, fastify.io)
reply.code(200).send('email sent')
}
})
fastify.route({
method: ['POST'],
url: '/save_template',
schema:{
security: [{cookieAuth: []}],
description: 'Save a local template',
tags: ['Template'],
summary: 'save local template',
body: {
type: 'object',
properties: {
template_name: {
type: 'string',
description: 'template name'
},
mail_data: {
type: 'string',
description: 'template MIME content'
}
}
},
response: {
200: {
description: 'Successful response',
type: 'string'
}
}
},
handler: async function (req, reply) {
console.log(":saved email template: \n")
let template = req.body
let new_template = db.prepare(`
INSERT INTO templates (name, email) VALUES ($template_name, $mail_data)
ON CONFLICT(name) DO UPDATE SET email=$mail_data
`)
new_template.run({template_name: template.template_name, mail_data: template.mail_data})
reply.code(200).send('Template Saved')
}
})
fastify.route({
method: ['DELETE'],
url: '/delete_template',
schema:{
security: [{cookieAuth: []}],
description: 'Delete a local template',
tags: ['Template'],
summary: 'delete local template',
body: {
type: 'object',
properties: {
template_name: {
type: 'string',
description: 'template name'
}
}
},
response: {
200: {
description: 'Successful response',
type: 'string'
}
}
},
handler: async function (req, reply) {
console.log(":deleted email template: \n")
let template = req.body
let new_template = db.prepare(`
DELETE FROM templates WHERE name = $template
`)
new_template.run({template: template.template_name})
reply.code(200).send('Template Deleted')
}
})
fastify.route({
method: ['POST'],
url: '/save_campaign',
schema:{
security: [{cookieAuth: []}],
description: 'Save email as a campaign',
tags: ['Campaign'],
summary: 'save campaign',
body: {
type: 'object',
properties: {
campaign: {
type: 'string',
default: 'test',
description: 'campaign name'
},
market_id:{
type: 'number',
default: 0,
description: 'ID of Phismarket template, if one was used'
},
dkim: {
type: 'boolean',
default: false,
description: 'should we DKIM sign the message'
},
mail_data: {
type: 'string',
description: 'raw email message'
},
target_id: {
type: 'string',
default: 'test',
description: 'unique ID of the target user'
},
secure_mail: {
type: 'boolean',
default: false,
description: 'Should we use TLS for this message'
},
supplied_custom_replacement: {
type: 'string',
description: 'custom placeholder for per-target replacements'
},
supplied_delay: {
type: 'string',
default: "30",
description: 'delay between emails'
},
supplied_first_name: {
type: 'string',
description: 'substitution placeholder for target first names'
},
supplied_from_address:{
type: 'string',
description: 'email FROM address'
},
supplied_from_title:{
type: 'string',
description: 'email alias name'
},
supplied_id_param:{
type: 'string',
description: 'tracking ID GET param name for the target'
},
supplied_last_name: {
type: 'string',
description: 'substitution placeholdder for the target first name'
},
supplied_link: {
type: 'string',
description: 'base link URL for the phishing link'
},
supplied_mail_server: {
type: 'string',
description: 'mail server to send the test to'
},
supplied_mail_to:{
type: 'string',
description: 'target email address'
},
supplied_password:{
type: 'string',
description: 'password for authenticated SMTP relay'
},
supplied_position:{
type: 'string',
description: 'substitution placeholder for the target position'
},
supplied_smtp_from: {
type: 'string',
description: 'SMTP mail from: field'
},
supplied_username: {
type: 'string',
description: 'username for authenticated SMTP relay'
},
market_id:{
type: 'number',
description: 'the ID of the phishmarket template if this was created from a remote template'
}
}
},
response: {
200: {
description: 'Successful response',
type: 'string'
}
}
},
handler: async function (req, reply) {
console.log(":saved campaign: \n")
let campaign = req.body
var dkim = 0
if (campaign.dkim) {
dkim = 1
}
var secure = 0
if (campaign.secure_mail) {
secure = 1
}
var delay = 30
if (
(typeof campaign.supplied_delay !== "undefined") &
(campaign.supplied_delay !== "")
) {
delay = parseInt(campaign.supplied_delay)
}
var new_campaign = db.prepare(
`INSERT INTO campaigns VALUES (
$name,
$email,
$mail_server,
$smtp_from,
$phishing_link,
$id_parameter,
$delay,
$secure,
$username,
$password,
$dkim,
$scheduled_start,
$start_timestamp,
$end_timestamp,
$is_sending,
$market_id
)`
)
new_campaign.run({
name: String(campaign.campaign_name),
email: campaign.mail_data,
mail_server: campaign.supplied_mail_server,
smtp_from: campaign.supplied_smtp_from,
phishing_link: campaign.supplied_link,
id_parameter: campaign.supplied_id_param,
delay: delay,
secure: secure,
username: campaign.supplied_username,
password: campaign.supplied_password,
dkim: dkim,
scheduled_start: null,
start_timestamp: null,
end_timestamp: null,
is_sending: 0,
market_id: campaign.market_id
})
reply.code(200).send('Saved Campaign')
}
})
fastify.route({
method: ['PUT'],
url: '/update_campaign',
schema:{
security: [{cookieAuth: []}],
description: 'Update a campaign',
tags: ['Campaign'],
summary: 'update campaign',
body: {
type: 'object',
properties: {
campaign: {
type: 'string',
default: 'test',
description: 'campaign name'
},
dkim: {
type: 'boolean',
default: false,
description: 'should we DKIM sign the message'
},
mail_data: {
type: 'string',
description: 'raw email message'
},
target_id: {
type: 'string',
default: 'test',
description: 'unique ID of the target user'
},
secure_mail: {
type: 'boolean',
default: false,
description: 'Should we use TLS for this message'