gophish-ruby 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -92,6 +92,7 @@ Templates define the email content for your phishing campaigns:
92
92
  # Create a basic email template
93
93
  template = Gophish::Template.new(
94
94
  name: "Security Awareness Test",
95
+ envelope_sender: "noreply@company.com", # Separate envelope sender for delivery
95
96
  subject: "Important Security Update Required",
96
97
  html: "<h1>Security Update</h1><p>Please click <a href='{{.URL}}'>here</a> to update your password.</p>",
97
98
  text: "Security Update\n\nPlease visit {{.URL}} to update your password."
@@ -105,7 +106,27 @@ else
105
106
  end
106
107
  ```
107
108
 
108
- ### 5. Create Your First Landing Page
109
+ ### 5. Create Your First SMTP Profile
110
+
111
+ SMTP profiles define how emails are sent in your campaigns:
112
+
113
+ ```ruby
114
+ # Create a basic SMTP profile
115
+ smtp = Gophish::Smtp.new(
116
+ name: "Company Mail Server",
117
+ host: "smtp.company.com",
118
+ from_address: "security@company.com"
119
+ )
120
+
121
+ if smtp.save
122
+ puts "✓ SMTP profile created successfully with ID: #{smtp.id}"
123
+ else
124
+ puts "✗ Failed to create SMTP profile:"
125
+ smtp.errors.full_messages.each { |error| puts " - #{error}" }
126
+ end
127
+ ```
128
+
129
+ ### 6. Create Your First Landing Page
109
130
 
110
131
  Landing pages are what users see when they click phishing links:
111
132
 
@@ -150,8 +171,326 @@ else
150
171
  end
151
172
  ```
152
173
 
174
+ ### 7. Create Your First Campaign
175
+
176
+ Now that you have all the components, you can create a complete phishing campaign:
177
+
178
+ ```ruby
179
+ # Create a campaign using the components you've created
180
+ campaign = Gophish::Campaign.new(
181
+ name: "Security Awareness Test Campaign",
182
+ template: { name: "Security Awareness Test" }, # Reference the template by name
183
+ page: { name: "Microsoft Login Page" }, # Reference the landing page by name
184
+ groups: [{ name: "My First Group" }], # Reference the group by name
185
+ smtp: { name: "Company Mail Server" }, # Reference the SMTP profile by name
186
+ url: "https://your-phishing-domain.com" # Your campaign tracking URL
187
+ )
188
+
189
+ if campaign.save
190
+ puts "✓ Campaign created successfully with ID: #{campaign.id}"
191
+ puts " Status: #{campaign.status}"
192
+ puts " Campaign URL: #{campaign.url}"
193
+ else
194
+ puts "✗ Failed to create campaign:"
195
+ campaign.errors.full_messages.each { |error| puts " - #{error}" }
196
+ end
197
+ ```
198
+
199
+ ### 8. Monitor Your Campaign
200
+
201
+ Once your campaign is created, you can monitor its progress:
202
+
203
+ ```ruby
204
+ # Find your campaign
205
+ campaign = Gophish::Campaign.find(1) # Replace with your campaign ID
206
+
207
+ puts "Campaign: #{campaign.name}"
208
+ puts "Status: #{campaign.status}"
209
+ puts "In progress? #{campaign.in_progress?}"
210
+ puts "Completed? #{campaign.completed?}"
211
+
212
+ # Get campaign results
213
+ if campaign.results.any?
214
+ puts "\nResults Summary:"
215
+ puts " Total targets: #{campaign.results.length}"
216
+
217
+ # Count interactions
218
+ clicked_count = campaign.results.count(&:clicked?)
219
+ opened_count = campaign.results.count(&:opened?)
220
+ reported_count = campaign.results.count(&:reported?)
221
+
222
+ puts " Emails opened: #{opened_count}"
223
+ puts " Links clicked: #{clicked_count}"
224
+ puts " Phishing reported: #{reported_count}"
225
+ puts " Click rate: #{(clicked_count.to_f / campaign.results.length * 100).round(1)}%"
226
+ else
227
+ puts "\nNo results yet - campaign may still be starting"
228
+ end
229
+ ```
230
+
231
+ ### Working with SMTP Profiles
232
+
233
+ #### Creating SMTP Profiles with Authentication
234
+
235
+ ```ruby
236
+ # SMTP profile with username/password authentication
237
+ smtp_auth = Gophish::Smtp.new(
238
+ name: "Gmail SMTP",
239
+ host: "smtp.gmail.com",
240
+ from_address: "phishing@company.com",
241
+ username: "smtp_user@company.com",
242
+ password: "app_specific_password",
243
+ ignore_cert_errors: false
244
+ )
245
+
246
+ puts "Uses authentication: #{smtp_auth.has_authentication?}"
247
+ smtp_auth.save
248
+ ```
249
+
250
+ #### Adding Custom Headers to SMTP Profiles
251
+
252
+ ```ruby
253
+ # SMTP profile with custom headers for better deliverability
254
+ smtp = Gophish::Smtp.new(
255
+ name: "Custom Headers SMTP",
256
+ host: "mail.company.com",
257
+ from_address: "security@company.com"
258
+ )
259
+
260
+ # Add headers for email routing and identification
261
+ smtp.add_header("X-Mailer", "Company Security Training")
262
+ smtp.add_header("X-Campaign-Type", "Phishing Simulation")
263
+ smtp.add_header("Return-Path", "bounces@company.com")
264
+
265
+ puts "Header count: #{smtp.header_count}"
266
+ smtp.save
267
+ ```
268
+
269
+ #### Managing Existing SMTP Profiles
270
+
271
+ ```ruby
272
+ # List all SMTP profiles
273
+ puts "Existing SMTP profiles:"
274
+ Gophish::Smtp.all.each do |smtp|
275
+ auth_info = smtp.has_authentication? ? " [Auth]" : ""
276
+ header_info = smtp.has_headers? ? " (#{smtp.header_count} headers)" : ""
277
+ puts " #{smtp.id}: #{smtp.name} (#{smtp.host})#{auth_info}#{header_info}"
278
+ end
279
+
280
+ # Update an SMTP profile
281
+ smtp = Gophish::Smtp.find(1)
282
+ smtp.name = "Updated Mail Server"
283
+ smtp.ignore_cert_errors = true # For testing environments
284
+
285
+ # Add new header
286
+ smtp.add_header("X-Priority", "High")
287
+
288
+ # Remove old header
289
+ smtp.remove_header("X-Campaign-Type")
290
+
291
+ if smtp.save
292
+ puts "✓ SMTP profile updated"
293
+ puts " Headers: #{smtp.header_count}"
294
+ end
295
+ ```
296
+
153
297
  ## Common Workflows
154
298
 
299
+ ### Complete Campaign Workflow
300
+
301
+ Here's a complete workflow showing how to create all components and run a campaign:
302
+
303
+ ```ruby
304
+ # Step 1: Create target group
305
+ group = Gophish::Group.new(name: "Security Training Q1")
306
+ csv_data = <<~CSV
307
+ First Name,Last Name,Email,Position
308
+ Alice,Johnson,alice@company.com,Developer
309
+ Bob,Smith,bob@company.com,Manager
310
+ Carol,Wilson,carol@company.com,Analyst
311
+ CSV
312
+ group.import_csv(csv_data)
313
+ group.save
314
+
315
+ # Step 2: Create email template with envelope sender
316
+ template = Gophish::Template.new(
317
+ name: "IT Security Update",
318
+ envelope_sender: "noreply@company.com",
319
+ subject: "Mandatory Security Update - Action Required",
320
+ html: <<~HTML
321
+ <html>
322
+ <body style="font-family: Arial, sans-serif;">
323
+ <div style="max-width: 600px; margin: 0 auto; padding: 20px;">
324
+ <h2 style="color: #d32f2f;">🔒 Security Alert</h2>
325
+ <p>Dear {{.FirstName}},</p>
326
+ <p>Our IT security team has detected unusual activity that requires immediate attention.</p>
327
+ <div style="background: #f5f5f5; padding: 15px; margin: 20px 0; border-left: 4px solid #d32f2f;">
328
+ <strong>Action Required:</strong> Please verify your account credentials immediately.
329
+ </div>
330
+ <p style="text-align: center;">
331
+ <a href="{{.URL}}" style="background: #1976d2; color: white; padding: 12px 24px; text-decoration: none; border-radius: 4px; display: inline-block;">
332
+ Verify Account Now
333
+ </a>
334
+ </p>
335
+ <p><small>This is a security training exercise. Report suspicious emails to IT.</small></p>
336
+ </div>
337
+ </body>
338
+ </html>
339
+ HTML
340
+ )
341
+ template.save
342
+
343
+ # Step 3: Create landing page
344
+ page = Gophish::Page.new(
345
+ name: "Corporate Login Portal",
346
+ html: <<~HTML
347
+ <!DOCTYPE html>
348
+ <html>
349
+ <head>
350
+ <title>Secure Login - Company Portal</title>
351
+ <style>
352
+ body { font-family: 'Segoe UI', Arial, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); margin: 0; padding: 40px 0; min-height: 100vh; }
353
+ .container { max-width: 400px; margin: 0 auto; background: white; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); overflow: hidden; }
354
+ .header { background: #1976d2; color: white; padding: 30px; text-align: center; }
355
+ .form { padding: 30px; }
356
+ .input-group { margin-bottom: 20px; }
357
+ input { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 5px; font-size: 14px; box-sizing: border-box; }
358
+ button { width: 100%; padding: 12px; background: #1976d2; color: white; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; }
359
+ button:hover { background: #1565c0; }
360
+ .footer { text-align: center; padding: 20px; color: #666; font-size: 12px; }
361
+ </style>
362
+ </head>
363
+ <body>
364
+ <div class="container">
365
+ <div class="header">
366
+ <h2>🏢 Company Portal</h2>
367
+ <p>Secure Employee Login</p>
368
+ </div>
369
+ <div class="form">
370
+ <form method="post">
371
+ <div class="input-group">
372
+ <input type="email" name="username" placeholder="Email Address" required>
373
+ </div>
374
+ <div class="input-group">
375
+ <input type="password" name="password" placeholder="Password" required>
376
+ </div>
377
+ <button type="submit">Sign In</button>
378
+ </form>
379
+ </div>
380
+ <div class="footer">
381
+ Protected by advanced security protocols
382
+ </div>
383
+ </div>
384
+ </body>
385
+ </html>
386
+ HTML,
387
+ capture_credentials: true,
388
+ capture_passwords: true,
389
+ redirect_url: "https://company.com/portal"
390
+ )
391
+ page.save
392
+
393
+ # Step 4: Create SMTP profile
394
+ smtp = Gophish::Smtp.new(
395
+ name: "Training SMTP Server",
396
+ host: "smtp.company.com",
397
+ from_address: "security@company.com"
398
+ )
399
+ smtp.add_header("X-Mailer", "Company Security Training")
400
+ smtp.add_header("X-Training-Campaign", "Q1-2024")
401
+ smtp.save
402
+
403
+ # Step 5: Create and launch campaign
404
+ campaign = Gophish::Campaign.new(
405
+ name: "Q1 2024 Security Awareness Training",
406
+ template: template,
407
+ page: page,
408
+ groups: [group],
409
+ smtp: smtp,
410
+ url: "https://training-portal.company.com"
411
+ )
412
+
413
+ if campaign.save
414
+ puts "🚀 Campaign launched successfully!"
415
+ puts " Campaign ID: #{campaign.id}"
416
+ puts " Template: #{campaign.template.name}"
417
+ puts " Landing Page: #{campaign.page.name}"
418
+ puts " Target Groups: #{campaign.groups.map(&:name).join(', ')}"
419
+ puts " SMTP Profile: #{campaign.smtp.name}"
420
+ puts " Total Targets: #{group.targets.length}"
421
+ end
422
+ ```
423
+
424
+ ### Campaign Management and Monitoring
425
+
426
+ ```ruby
427
+ # Monitor campaign progress
428
+ campaign = Gophish::Campaign.find(1)
429
+
430
+ # Check status
431
+ puts "Campaign Status: #{campaign.status}"
432
+ puts "In Progress? #{campaign.in_progress?}"
433
+
434
+ # Analyze results in detail
435
+ if campaign.results.any?
436
+ puts "\n📊 Detailed Campaign Results:"
437
+
438
+ # Group results by status
439
+ status_counts = Hash.new(0)
440
+ campaign.results.each { |result| status_counts[result.status] += 1 }
441
+
442
+ status_counts.each do |status, count|
443
+ percentage = (count.to_f / campaign.results.length * 100).round(1)
444
+ puts " #{status}: #{count} (#{percentage}%)"
445
+ end
446
+
447
+ # Show individual results
448
+ puts "\n👤 Individual Results:"
449
+ campaign.results.each do |result|
450
+ status_icon = result.clicked? ? "🔗" : result.opened? ? "📧" : result.reported? ? "🚨" : "📬"
451
+ puts " #{status_icon} #{result.email} - #{result.status}"
452
+ end
453
+
454
+ # Timeline analysis
455
+ if campaign.timeline.any?
456
+ puts "\n📅 Recent Timeline Events:"
457
+ campaign.timeline.last(5).each do |event|
458
+ puts " #{event.time}: #{event.message}"
459
+ end
460
+ end
461
+ end
462
+
463
+ # Complete campaign if needed
464
+ if campaign.in_progress?
465
+ puts "\n⏹️ Completing campaign..."
466
+ result = campaign.complete!
467
+ puts result['success'] ? "✅ Campaign completed" : "❌ Failed to complete"
468
+ end
469
+ ```
470
+
471
+ ### Advanced Campaign Scheduling
472
+
473
+ ```ruby
474
+ # Create a scheduled campaign with specific timing
475
+ future_campaign = Gophish::Campaign.new(
476
+ name: "Scheduled Phishing Test - Monday Morning",
477
+ template: { name: "IT Security Update" },
478
+ page: { name: "Corporate Login Portal" },
479
+ groups: [{ name: "Security Training Q1" }],
480
+ smtp: { name: "Training SMTP Server" },
481
+ url: "https://training-portal.company.com",
482
+ launch_date: (Date.today + 7).beginning_of_day.iso8601, # Next Monday at midnight
483
+ send_by_date: (Date.today + 7).noon.iso8601 # Complete by noon
484
+ )
485
+
486
+ if future_campaign.save
487
+ puts "📅 Scheduled campaign created for #{future_campaign.launch_date}"
488
+ puts " Will complete by: #{future_campaign.send_by_date}"
489
+ puts " Launched? #{future_campaign.launched?}"
490
+ puts " Has deadline? #{future_campaign.has_send_by_date?}"
491
+ end
492
+ ```
493
+
155
494
  ### Importing Targets from CSV
156
495
 
157
496
  The most common use case is importing a list of targets from a CSV file:
@@ -193,12 +532,36 @@ end
193
532
 
194
533
  ### Working with Templates
195
534
 
535
+ #### Creating Templates with Envelope Sender
536
+
537
+ ```ruby
538
+ # Create template with envelope sender for better email delivery control
539
+ template = Gophish::Template.new(
540
+ name: "Corporate Update Template",
541
+ envelope_sender: "noreply@company.com", # Envelope sender (bounce address)
542
+ subject: "Important Corporate Update",
543
+ html: <<~HTML
544
+ <div style="font-family: Arial, sans-serif;">
545
+ <h2>IT Security Department</h2>
546
+ <p>Dear {{.FirstName}} {{.LastName}},</p>
547
+ <p>We need to update your security credentials immediately.</p>
548
+ <p><a href="{{.URL}}" style="background: #0066cc; color: white; padding: 10px 20px; text-decoration: none;">Update Now</a></p>
549
+ <p>Best regards,<br>IT Security Team</p>
550
+ </div>
551
+ HTML
552
+ )
553
+
554
+ puts "Has envelope sender: #{template.has_envelope_sender?}"
555
+ template.save
556
+ ```
557
+
196
558
  #### Creating Templates with Attachments
197
559
 
198
560
  ```ruby
199
561
  # Create template with file attachments
200
562
  template = Gophish::Template.new(
201
563
  name: "Invoice Template",
564
+ envelope_sender: "billing@company.com",
202
565
  subject: "Your Invoice #{{.RId}}",
203
566
  html: "<p>Dear {{.FirstName}},</p><p>Please find your invoice attached.</p>"
204
567
  )