gophish-ruby 0.1.0 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -0
- data/README.md +342 -2
- data/Rakefile +1 -1
- data/docs/API_REFERENCE.md +572 -4
- data/docs/EXAMPLES.md +984 -0
- data/docs/GETTING_STARTED.md +239 -0
- data/lib/gophish/base.rb +6 -24
- data/lib/gophish/group.rb +2 -0
- data/lib/gophish/page.rb +56 -0
- data/lib/gophish/template.rb +94 -0
- data/lib/gophish/version.rb +1 -1
- data/lib/gophish-ruby.rb +2 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abf879c22c4f9f1521c61af8ebc635956ba6f70b3d6292019707b34168c32c73
|
4
|
+
data.tar.gz: 41e2452769f172e282a83f0e6a4d186e82f4544683f405745790f736532a03d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b1d75bff457c5f276fa014daffeff9834b9d44771a2dd2d41b12353d3060ff5b04fd5665aaf92a93417ababfaef3a26acc48edee5c4d165cde3c69b0749b47b
|
7
|
+
data.tar.gz: 702c43a976ae0ab06dbaa49ad01e7631b0b2a5405a6d41a13384f8c3e2b58c339d04b143fc78f65940119d52c5851bb17ae7c464c2e8c783ba82f468dfae5a42
|
data/CHANGELOG.md
CHANGED
@@ -7,21 +7,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.3.0] - 2025-01-15
|
11
|
+
|
10
12
|
### Added
|
13
|
+
|
14
|
+
- **Page Management System**
|
15
|
+
- `Gophish::Page` class for managing landing pages in phishing campaigns
|
16
|
+
- Full CRUD operations for pages (create, read, update, delete)
|
17
|
+
- Support for HTML content with credential capture capabilities
|
18
|
+
- Comprehensive validations requiring page name and HTML content
|
19
|
+
- Site import functionality with `Page.import_site` class method
|
20
|
+
- Option to include resources (CSS, JS, images) during site import
|
21
|
+
- Built-in methods for checking page configuration: `#captures_credentials?`, `#captures_passwords?`, `#has_redirect?`
|
22
|
+
|
23
|
+
- **Template Management System**
|
24
|
+
- `Gophish::Template` class for managing email templates
|
25
|
+
- Full CRUD operations for templates (create, read, update, delete)
|
26
|
+
- Support for HTML and plain text email content
|
27
|
+
- Comprehensive validations requiring template name and content
|
28
|
+
- Email import functionality with `Template.import_email` class method
|
29
|
+
- Option to convert links during email import for tracking
|
30
|
+
|
31
|
+
- **Attachment Management**
|
32
|
+
- Add attachments to templates with `#add_attachment` method
|
33
|
+
- Remove attachments by name with `#remove_attachment` method
|
34
|
+
- Query attachment status with `#has_attachments?` and `#attachment_count`
|
35
|
+
- Automatic Base64 encoding of attachment content
|
36
|
+
- Validation of attachment structure (content, type, name required)
|
37
|
+
|
38
|
+
- **Enhanced Change Tracking**
|
39
|
+
- Migrated from custom change tracking to ActiveModel::Dirty
|
40
|
+
- Improved change detection with `#changed?` and `#clear_changes_information`
|
41
|
+
- Better integration with Rails-style attribute tracking
|
42
|
+
|
11
43
|
- Comprehensive documentation with getting started guide, API reference, and examples
|
12
44
|
- Enhanced README with detailed usage instructions and configuration examples
|
13
45
|
|
14
46
|
### Changed
|
47
|
+
|
48
|
+
- **Breaking Change**: Replaced custom `@changed_attributes` system with ActiveModel::Dirty
|
49
|
+
- Updated Base class to use `define_attribute_methods` for proper dirty tracking
|
50
|
+
- Modified `#update_record` to include `id` in update payload for proper API calls
|
15
51
|
- Improved error messages for validation failures
|
16
52
|
- Enhanced CSV import validation with better error reporting
|
17
53
|
|
18
54
|
### Fixed
|
55
|
+
|
19
56
|
- Console script requiring wrong file name (`gophish_ruby` → `gophish-ruby`)
|
20
57
|
- Spec helper requiring wrong file name for consistent naming
|
58
|
+
- Corrected require statement in main library file for Template class
|
21
59
|
|
22
60
|
## [0.1.0] - 2025-08-29
|
23
61
|
|
24
62
|
### Added
|
63
|
+
|
25
64
|
- **Core SDK Foundation**
|
26
65
|
- `Gophish::Configuration` class for managing API credentials and settings
|
27
66
|
- `Gophish::Base` abstract class providing common CRUD operations
|
@@ -68,12 +107,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
68
107
|
- Rake tasks for testing and quality checks
|
69
108
|
|
70
109
|
### Technical Details
|
110
|
+
|
71
111
|
- **Dependencies**: HTTParty 0.23.1, ActiveSupport/ActiveModel/ActiveRecord 8.0+
|
72
112
|
- **Ruby Version**: Requires Ruby >= 3.1.0
|
73
113
|
- **Architecture**: Modular design with inheritance-based API resources
|
74
114
|
- **Security**: Built-in API key authentication for all requests
|
75
115
|
|
76
116
|
### Development Infrastructure
|
117
|
+
|
77
118
|
- Bundler gem management with proper gemspec configuration
|
78
119
|
- GitHub integration with proper repository URLs and metadata
|
79
120
|
- MIT license for open source distribution
|
data/README.md
CHANGED
@@ -11,9 +11,13 @@ A Ruby SDK for the [Gophish](https://getgophish.com/) phishing simulation platfo
|
|
11
11
|
- **ActiveModel Integration**: Familiar Rails-like attributes, validations, and callbacks
|
12
12
|
- **Automatic Authentication**: Built-in API key authentication for all requests
|
13
13
|
- **CSV Import Support**: Easy bulk import of targets from CSV files
|
14
|
+
- **Email Template Management**: Create, modify, and manage email templates with attachment support
|
15
|
+
- **Email Import**: Import existing emails and convert them to templates
|
16
|
+
- **Site Import**: Import landing pages directly from existing websites
|
17
|
+
- **Page Management**: Create, modify, and manage landing pages with credential capture
|
14
18
|
- **SSL Configuration**: Configurable SSL verification for development environments
|
15
19
|
- **Debug Support**: Built-in debugging capabilities for API interactions
|
16
|
-
- **Change Tracking**: Automatic tracking of attribute changes
|
20
|
+
- **Change Tracking**: Automatic tracking of attribute changes with ActiveModel::Dirty
|
17
21
|
- **Comprehensive Validation**: Built-in validations for all data models
|
18
22
|
|
19
23
|
## Installation
|
@@ -184,9 +188,110 @@ unless group.valid?
|
|
184
188
|
end
|
185
189
|
```
|
186
190
|
|
191
|
+
### Templates Management
|
192
|
+
|
193
|
+
Templates define the email content for your phishing campaigns, including HTML/text content and attachments.
|
194
|
+
|
195
|
+
#### Creating a Template
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
# Create a new email template
|
199
|
+
template = Gophish::Template.new(
|
200
|
+
name: "Phishing Awareness Test",
|
201
|
+
subject: "Security Update Required",
|
202
|
+
html: "<h1>Important Security Update</h1><p>Please click <a href='{{.URL}}'>here</a> to update your password.</p>",
|
203
|
+
text: "Important Security Update\n\nPlease visit {{.URL}} to update your password."
|
204
|
+
)
|
205
|
+
|
206
|
+
if template.save
|
207
|
+
puts "Template created successfully with ID: #{template.id}"
|
208
|
+
else
|
209
|
+
puts "Failed to create template: #{template.errors.full_messages}"
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
#### Adding Attachments
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
template = Gophish::Template.new(
|
217
|
+
name: "Invoice Template",
|
218
|
+
subject: "Invoice #12345",
|
219
|
+
html: "<p>Please find your invoice attached.</p>"
|
220
|
+
)
|
221
|
+
|
222
|
+
# Add an attachment
|
223
|
+
file_content = File.read("path/to/invoice.pdf")
|
224
|
+
template.add_attachment(file_content, "application/pdf", "invoice.pdf")
|
225
|
+
|
226
|
+
puts "Template has #{template.attachment_count} attachments"
|
227
|
+
```
|
228
|
+
|
229
|
+
#### Managing Attachments
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
# Check if template has attachments
|
233
|
+
if template.has_attachments?
|
234
|
+
puts "Template has attachments"
|
235
|
+
end
|
236
|
+
|
237
|
+
# Remove an attachment by name
|
238
|
+
template.remove_attachment("invoice.pdf")
|
239
|
+
puts "Attachments remaining: #{template.attachment_count}"
|
240
|
+
```
|
241
|
+
|
242
|
+
#### Importing Email Content
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
# Import an existing email (.eml file content)
|
246
|
+
email_content = File.read("path/to/email.eml")
|
247
|
+
|
248
|
+
imported_data = Gophish::Template.import_email(
|
249
|
+
email_content,
|
250
|
+
convert_links: true # Convert links to Gophish tracking format
|
251
|
+
)
|
252
|
+
|
253
|
+
# Create template from imported data
|
254
|
+
template = Gophish::Template.new(imported_data)
|
255
|
+
template.name = "Imported Email Template"
|
256
|
+
template.save
|
257
|
+
```
|
258
|
+
|
259
|
+
#### Retrieving Templates
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
# Get all templates
|
263
|
+
templates = Gophish::Template.all
|
264
|
+
puts "Found #{templates.length} templates"
|
265
|
+
|
266
|
+
# Find a specific template by ID
|
267
|
+
template = Gophish::Template.find(1)
|
268
|
+
puts "Template: #{template.name}"
|
269
|
+
```
|
270
|
+
|
271
|
+
#### Updating a Template
|
272
|
+
|
273
|
+
```ruby
|
274
|
+
template = Gophish::Template.find(1)
|
275
|
+
template.subject = "Updated Subject Line"
|
276
|
+
template.html = "<h1>Updated Content</h1>"
|
277
|
+
|
278
|
+
if template.save
|
279
|
+
puts "Template updated successfully"
|
280
|
+
end
|
281
|
+
```
|
282
|
+
|
283
|
+
#### Deleting a Template
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
template = Gophish::Template.find(1)
|
287
|
+
if template.destroy
|
288
|
+
puts "Template deleted successfully"
|
289
|
+
end
|
290
|
+
```
|
291
|
+
|
187
292
|
### Change Tracking
|
188
293
|
|
189
|
-
The SDK automatically tracks changes to attributes:
|
294
|
+
The SDK automatically tracks changes to attributes using ActiveModel::Dirty:
|
190
295
|
|
191
296
|
```ruby
|
192
297
|
group = Gophish::Group.find(1)
|
@@ -198,6 +303,174 @@ puts group.attribute_changed?(:name) # => true
|
|
198
303
|
puts group.attribute_was(:name) # => "Original Name"
|
199
304
|
```
|
200
305
|
|
306
|
+
### Pages Management
|
307
|
+
|
308
|
+
Pages represent landing pages that targets will see when they click on phishing links in your campaigns.
|
309
|
+
|
310
|
+
#### Creating a Page
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
# Create a simple landing page
|
314
|
+
page = Gophish::Page.new(
|
315
|
+
name: "Microsoft Login Page",
|
316
|
+
html: <<~HTML
|
317
|
+
<!DOCTYPE html>
|
318
|
+
<html>
|
319
|
+
<head>
|
320
|
+
<title>Microsoft Account Login</title>
|
321
|
+
<style>
|
322
|
+
body { font-family: Arial, sans-serif; margin: 0; padding: 40px; background-color: #f5f5f5; }
|
323
|
+
.login-container { max-width: 400px; margin: 0 auto; background: white; padding: 40px; border-radius: 8px; }
|
324
|
+
.form-group { margin-bottom: 20px; }
|
325
|
+
input { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 4px; }
|
326
|
+
button { width: 100%; padding: 12px; background: #0078d4; color: white; border: none; border-radius: 4px; }
|
327
|
+
</style>
|
328
|
+
</head>
|
329
|
+
<body>
|
330
|
+
<div class="login-container">
|
331
|
+
<h2>Sign in to your account</h2>
|
332
|
+
<form method="post">
|
333
|
+
<div class="form-group">
|
334
|
+
<input type="email" name="email" placeholder="Email" required>
|
335
|
+
</div>
|
336
|
+
<div class="form-group">
|
337
|
+
<input type="password" name="password" placeholder="Password" required>
|
338
|
+
</div>
|
339
|
+
<button type="submit">Sign in</button>
|
340
|
+
</form>
|
341
|
+
</div>
|
342
|
+
</body>
|
343
|
+
</html>
|
344
|
+
HTML
|
345
|
+
)
|
346
|
+
|
347
|
+
# Save the page to Gophish
|
348
|
+
if page.save
|
349
|
+
puts "Page created successfully with ID: #{page.id}"
|
350
|
+
else
|
351
|
+
puts "Failed to create page: #{page.errors.full_messages}"
|
352
|
+
end
|
353
|
+
```
|
354
|
+
|
355
|
+
#### Creating a Page with Credential Capture
|
356
|
+
|
357
|
+
```ruby
|
358
|
+
# Create a page that captures login credentials
|
359
|
+
page = Gophish::Page.new(
|
360
|
+
name: "Banking Login - Credential Capture",
|
361
|
+
html: <<~HTML
|
362
|
+
<html>
|
363
|
+
<body>
|
364
|
+
<h1>Online Banking</h1>
|
365
|
+
<form method="post">
|
366
|
+
<input type="text" name="username" placeholder="Username" required>
|
367
|
+
<input type="password" name="password" placeholder="Password" required>
|
368
|
+
<button type="submit">Login</button>
|
369
|
+
</form>
|
370
|
+
</body>
|
371
|
+
</html>
|
372
|
+
HTML,
|
373
|
+
capture_credentials: true,
|
374
|
+
capture_passwords: true,
|
375
|
+
redirect_url: "https://www.realbank.com/login"
|
376
|
+
)
|
377
|
+
|
378
|
+
if page.save
|
379
|
+
puts "Page created with credential capture enabled"
|
380
|
+
puts "Captures credentials: #{page.captures_credentials?}"
|
381
|
+
puts "Captures passwords: #{page.captures_passwords?}"
|
382
|
+
puts "Has redirect: #{page.has_redirect?}"
|
383
|
+
end
|
384
|
+
```
|
385
|
+
|
386
|
+
#### Importing a Website as a Landing Page
|
387
|
+
|
388
|
+
```ruby
|
389
|
+
# Import an existing website as a landing page template
|
390
|
+
begin
|
391
|
+
imported_data = Gophish::Page.import_site(
|
392
|
+
"https://login.microsoft.com",
|
393
|
+
include_resources: true # Include CSS, JS, and images
|
394
|
+
)
|
395
|
+
|
396
|
+
# Create a page from the imported data
|
397
|
+
page = Gophish::Page.new(imported_data)
|
398
|
+
page.name = "Imported Microsoft Login Page"
|
399
|
+
page.capture_credentials = true
|
400
|
+
|
401
|
+
if page.save
|
402
|
+
puts "Successfully imported and created page from website"
|
403
|
+
end
|
404
|
+
rescue StandardError => e
|
405
|
+
puts "Failed to import site: #{e.message}"
|
406
|
+
end
|
407
|
+
```
|
408
|
+
|
409
|
+
#### Retrieving Pages
|
410
|
+
|
411
|
+
```ruby
|
412
|
+
# Get all pages
|
413
|
+
pages = Gophish::Page.all
|
414
|
+
puts "Found #{pages.length} pages"
|
415
|
+
|
416
|
+
# Find a specific page by ID
|
417
|
+
page = Gophish::Page.find(1)
|
418
|
+
puts "Page: #{page.name}"
|
419
|
+
puts "HTML length: #{page.html.length} characters"
|
420
|
+
```
|
421
|
+
|
422
|
+
#### Updating a Page
|
423
|
+
|
424
|
+
```ruby
|
425
|
+
# Update page content and settings
|
426
|
+
page = Gophish::Page.find(1)
|
427
|
+
page.name = "Updated Page Name"
|
428
|
+
page.capture_credentials = true
|
429
|
+
page.redirect_url = "https://example.com/success"
|
430
|
+
|
431
|
+
# Update HTML content
|
432
|
+
page.html = page.html.gsub("Sign in", "Login")
|
433
|
+
|
434
|
+
if page.save
|
435
|
+
puts "Page updated successfully"
|
436
|
+
end
|
437
|
+
```
|
438
|
+
|
439
|
+
#### Deleting a Page
|
440
|
+
|
441
|
+
```ruby
|
442
|
+
page = Gophish::Page.find(1)
|
443
|
+
if page.destroy
|
444
|
+
puts "Page deleted successfully"
|
445
|
+
end
|
446
|
+
```
|
447
|
+
|
448
|
+
### Validation and Error Handling
|
449
|
+
|
450
|
+
The SDK provides comprehensive validation for pages:
|
451
|
+
|
452
|
+
```ruby
|
453
|
+
# Invalid page (missing required fields)
|
454
|
+
page = Gophish::Page.new(name: "", html: "")
|
455
|
+
|
456
|
+
unless page.valid?
|
457
|
+
puts "Validation errors:"
|
458
|
+
page.errors.full_messages.each { |msg| puts " - #{msg}" }
|
459
|
+
# => ["Name can't be blank", "Html can't be blank"]
|
460
|
+
end
|
461
|
+
|
462
|
+
# Check page configuration
|
463
|
+
page = Gophish::Page.new(
|
464
|
+
name: "Test Page",
|
465
|
+
html: "<html><body>Test</body></html>",
|
466
|
+
capture_credentials: true
|
467
|
+
)
|
468
|
+
|
469
|
+
if page.captures_credentials?
|
470
|
+
puts "This page will capture submitted credentials"
|
471
|
+
end
|
472
|
+
```
|
473
|
+
|
201
474
|
## API Documentation
|
202
475
|
|
203
476
|
### Core Classes
|
@@ -258,6 +531,73 @@ Each target in the `targets` array should have:
|
|
258
531
|
|
259
532
|
- `#import_csv(csv_data)` - Import targets from CSV data
|
260
533
|
|
534
|
+
#### `Gophish::Template`
|
535
|
+
|
536
|
+
Represents a Gophish email template.
|
537
|
+
|
538
|
+
**Attributes:**
|
539
|
+
|
540
|
+
- `id` (Integer) - Unique template identifier
|
541
|
+
- `name` (String) - Template name (required)
|
542
|
+
- `subject` (String) - Email subject line
|
543
|
+
- `text` (String) - Plain text email content
|
544
|
+
- `html` (String) - HTML email content
|
545
|
+
- `modified_date` (String) - Last modification timestamp
|
546
|
+
- `attachments` (Array) - Array of attachment hashes
|
547
|
+
|
548
|
+
**Attachment Structure:**
|
549
|
+
Each attachment in the `attachments` array should have:
|
550
|
+
|
551
|
+
- `content` (String) - Base64 encoded file content (required)
|
552
|
+
- `type` (String) - MIME type of the attachment (required)
|
553
|
+
- `name` (String) - Filename of the attachment (required)
|
554
|
+
|
555
|
+
**Class Methods:**
|
556
|
+
|
557
|
+
- `.import_email(content, convert_links: false)` - Import email content and return template data
|
558
|
+
|
559
|
+
**Instance Methods:**
|
560
|
+
|
561
|
+
- `#add_attachment(content, type, name)` - Add an attachment to the template
|
562
|
+
- `#remove_attachment(name)` - Remove an attachment by filename
|
563
|
+
- `#has_attachments?` - Check if template has any attachments
|
564
|
+
- `#attachment_count` - Get the number of attachments
|
565
|
+
|
566
|
+
**Validations:**
|
567
|
+
|
568
|
+
- Template must have a name
|
569
|
+
- Template must have either text or HTML content (or both)
|
570
|
+
- All attachments must have content, type, and name
|
571
|
+
|
572
|
+
#### `Gophish::Page`
|
573
|
+
|
574
|
+
Represents a Gophish landing page for phishing campaigns.
|
575
|
+
|
576
|
+
**Attributes:**
|
577
|
+
|
578
|
+
- `id` (Integer) - Unique page identifier
|
579
|
+
- `name` (String) - Page name (required)
|
580
|
+
- `html` (String) - HTML content of the page (required)
|
581
|
+
- `capture_credentials` (Boolean) - Whether to capture credentials (default: false)
|
582
|
+
- `capture_passwords` (Boolean) - Whether to capture passwords (default: false)
|
583
|
+
- `redirect_url` (String) - URL to redirect users after form submission
|
584
|
+
- `modified_date` (String) - Last modification timestamp
|
585
|
+
|
586
|
+
**Class Methods:**
|
587
|
+
|
588
|
+
- `.import_site(url, include_resources: false)` - Import a website as a landing page template
|
589
|
+
|
590
|
+
**Instance Methods:**
|
591
|
+
|
592
|
+
- `#captures_credentials?` - Check if page is configured to capture credentials
|
593
|
+
- `#captures_passwords?` - Check if page is configured to capture passwords
|
594
|
+
- `#has_redirect?` - Check if page has a redirect URL configured
|
595
|
+
|
596
|
+
**Validations:**
|
597
|
+
|
598
|
+
- Page must have a name
|
599
|
+
- Page must have HTML content
|
600
|
+
|
261
601
|
## Development
|
262
602
|
|
263
603
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|