gophish-ruby 0.1.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +295 -0
- data/CHANGELOG.md +83 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +340 -0
- data/Rakefile +12 -0
- data/docs/API_REFERENCE.md +512 -0
- data/docs/EXAMPLES.md +665 -0
- data/docs/GETTING_STARTED.md +340 -0
- data/lib/gophish/base.rb +206 -0
- data/lib/gophish/configuration.rb +5 -0
- data/lib/gophish/group.rb +72 -0
- data/lib/gophish/version.rb +5 -0
- data/lib/gophish-ruby.rb +18 -0
- data/sig/gophish/ruby.rbs +6 -0
- metadata +137 -0
data/README.md
ADDED
@@ -0,0 +1,340 @@
|
|
1
|
+
# Gophish Ruby SDK
|
2
|
+
|
3
|
+
A Ruby SDK for the [Gophish](https://getgophish.com/) phishing simulation platform. This gem provides a comprehensive interface to interact with the Gophish API, enabling security professionals to programmatically manage phishing campaigns for security awareness training.
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/gophish-ruby)
|
6
|
+
[](https://www.ruby-lang.org)
|
7
|
+
|
8
|
+
## Features
|
9
|
+
|
10
|
+
- **Full API Coverage**: Complete implementation of Gophish API endpoints
|
11
|
+
- **ActiveModel Integration**: Familiar Rails-like attributes, validations, and callbacks
|
12
|
+
- **Automatic Authentication**: Built-in API key authentication for all requests
|
13
|
+
- **CSV Import Support**: Easy bulk import of targets from CSV files
|
14
|
+
- **SSL Configuration**: Configurable SSL verification for development environments
|
15
|
+
- **Debug Support**: Built-in debugging capabilities for API interactions
|
16
|
+
- **Change Tracking**: Automatic tracking of attribute changes
|
17
|
+
- **Comprehensive Validation**: Built-in validations for all data models
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'gophish-ruby'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
bundle install
|
31
|
+
```
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
```bash
|
36
|
+
gem install gophish-ruby
|
37
|
+
```
|
38
|
+
|
39
|
+
## Configuration
|
40
|
+
|
41
|
+
Before using the SDK, you need to configure it with your Gophish API credentials:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'gophish-ruby'
|
45
|
+
|
46
|
+
Gophish.configure do |config|
|
47
|
+
config.url = "https://your-gophish-server.com"
|
48
|
+
config.api_key = "your-api-key-here"
|
49
|
+
config.verify_ssl = true # Set to false for development/self-signed certificates
|
50
|
+
config.debug_output = false # Set to true to see HTTP debug information
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
### Configuration Options
|
55
|
+
|
56
|
+
- **`url`**: The base URL of your Gophish server (e.g., `https://gophish.example.com`)
|
57
|
+
- **`api_key`**: Your Gophish API key (found in the Gophish admin panel)
|
58
|
+
- **`verify_ssl`**: Whether to verify SSL certificates (default: `true`)
|
59
|
+
- **`debug_output`**: Enable HTTP debugging output (default: `false`)
|
60
|
+
|
61
|
+
## Usage
|
62
|
+
|
63
|
+
### Groups Management
|
64
|
+
|
65
|
+
Groups represent collections of targets for your phishing campaigns.
|
66
|
+
|
67
|
+
#### Creating a Group
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# Create a new group with targets
|
71
|
+
group = Gophish::Group.new(
|
72
|
+
name: "Marketing Department",
|
73
|
+
targets: [
|
74
|
+
{
|
75
|
+
first_name: "John",
|
76
|
+
last_name: "Doe",
|
77
|
+
email: "john.doe@company.com",
|
78
|
+
position: "Marketing Manager"
|
79
|
+
},
|
80
|
+
{
|
81
|
+
first_name: "Jane",
|
82
|
+
last_name: "Smith",
|
83
|
+
email: "jane.smith@company.com",
|
84
|
+
position: "Marketing Coordinator"
|
85
|
+
}
|
86
|
+
]
|
87
|
+
)
|
88
|
+
|
89
|
+
# Save the group to Gophish
|
90
|
+
if group.save
|
91
|
+
puts "Group created successfully with ID: #{group.id}"
|
92
|
+
else
|
93
|
+
puts "Failed to create group: #{group.errors.full_messages}"
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
#### Importing from CSV
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
# CSV format: First Name,Last Name,Email,Position
|
101
|
+
csv_data = <<~CSV
|
102
|
+
First Name,Last Name,Email,Position
|
103
|
+
Alice,Johnson,alice@company.com,Developer
|
104
|
+
Bob,Wilson,bob@company.com,Designer
|
105
|
+
Carol,Brown,carol@company.com,Manager
|
106
|
+
CSV
|
107
|
+
|
108
|
+
group = Gophish::Group.new(name: "Development Team")
|
109
|
+
group.import_csv(csv_data)
|
110
|
+
|
111
|
+
if group.save
|
112
|
+
puts "Group created with #{group.targets.length} targets"
|
113
|
+
end
|
114
|
+
```
|
115
|
+
|
116
|
+
#### Retrieving Groups
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
# Get all groups
|
120
|
+
groups = Gophish::Group.all
|
121
|
+
puts "Found #{groups.length} groups"
|
122
|
+
|
123
|
+
# Find a specific group by ID
|
124
|
+
group = Gophish::Group.find(1)
|
125
|
+
puts "Group: #{group.name} with #{group.targets.length} targets"
|
126
|
+
```
|
127
|
+
|
128
|
+
#### Updating a Group
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
# Update group attributes
|
132
|
+
group = Gophish::Group.find(1)
|
133
|
+
group.name = "Updated Group Name"
|
134
|
+
|
135
|
+
# Add new targets
|
136
|
+
group.targets << {
|
137
|
+
first_name: "New",
|
138
|
+
last_name: "User",
|
139
|
+
email: "new.user@company.com",
|
140
|
+
position: "Intern"
|
141
|
+
}
|
142
|
+
|
143
|
+
if group.save
|
144
|
+
puts "Group updated successfully"
|
145
|
+
end
|
146
|
+
```
|
147
|
+
|
148
|
+
#### Deleting a Group
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
group = Gophish::Group.find(1)
|
152
|
+
if group.destroy
|
153
|
+
puts "Group deleted successfully"
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
### Validation and Error Handling
|
158
|
+
|
159
|
+
The SDK provides comprehensive validation:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
# Invalid group (missing required fields)
|
163
|
+
group = Gophish::Group.new(name: "")
|
164
|
+
|
165
|
+
unless group.valid?
|
166
|
+
puts "Validation errors:"
|
167
|
+
group.errors.full_messages.each { |msg| puts " - #{msg}" }
|
168
|
+
end
|
169
|
+
|
170
|
+
# Invalid email format
|
171
|
+
group = Gophish::Group.new(
|
172
|
+
name: "Test Group",
|
173
|
+
targets: [{
|
174
|
+
first_name: "John",
|
175
|
+
last_name: "Doe",
|
176
|
+
email: "invalid-email", # Invalid email format
|
177
|
+
position: "Manager"
|
178
|
+
}]
|
179
|
+
)
|
180
|
+
|
181
|
+
unless group.valid?
|
182
|
+
puts group.errors.full_messages
|
183
|
+
# => ["Targets item at index 0 must have a valid email format"]
|
184
|
+
end
|
185
|
+
```
|
186
|
+
|
187
|
+
### Change Tracking
|
188
|
+
|
189
|
+
The SDK automatically tracks changes to attributes:
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
group = Gophish::Group.find(1)
|
193
|
+
group.name = "New Name"
|
194
|
+
|
195
|
+
# Check if attributes have changed
|
196
|
+
puts group.changed_attributes # => ["name"]
|
197
|
+
puts group.attribute_changed?(:name) # => true
|
198
|
+
puts group.attribute_was(:name) # => "Original Name"
|
199
|
+
```
|
200
|
+
|
201
|
+
## API Documentation
|
202
|
+
|
203
|
+
### Core Classes
|
204
|
+
|
205
|
+
#### `Gophish::Configuration`
|
206
|
+
|
207
|
+
Manages SDK configuration including API credentials and connection settings.
|
208
|
+
|
209
|
+
**Attributes:**
|
210
|
+
|
211
|
+
- `url` (String) - Gophish server URL
|
212
|
+
- `api_key` (String) - API authentication key
|
213
|
+
- `verify_ssl` (Boolean) - SSL certificate verification
|
214
|
+
- `debug_output` (Boolean) - HTTP debug output
|
215
|
+
|
216
|
+
#### `Gophish::Base`
|
217
|
+
|
218
|
+
Abstract base class providing common functionality for all API resources.
|
219
|
+
|
220
|
+
**Class Methods:**
|
221
|
+
|
222
|
+
- `.all` - Retrieve all resources
|
223
|
+
- `.find(id)` - Find resource by ID
|
224
|
+
- `.resource_name` - Get the resource name for API endpoints
|
225
|
+
- `.resource_path` - Get the API path for the resource
|
226
|
+
|
227
|
+
**Instance Methods:**
|
228
|
+
|
229
|
+
- `#save` - Create or update the resource
|
230
|
+
- `#destroy` - Delete the resource
|
231
|
+
- `#valid?` - Check if the resource is valid
|
232
|
+
- `#persisted?` - Check if the resource is saved to the server
|
233
|
+
- `#new_record?` - Check if the resource is new (not yet saved)
|
234
|
+
- `#changed_attributes` - Get array of changed attribute names
|
235
|
+
- `#attribute_changed?(attr)` - Check if specific attribute changed
|
236
|
+
- `#attribute_was(attr)` - Get previous value of changed attribute
|
237
|
+
|
238
|
+
#### `Gophish::Group`
|
239
|
+
|
240
|
+
Represents a Gophish target group.
|
241
|
+
|
242
|
+
**Attributes:**
|
243
|
+
|
244
|
+
- `id` (Integer) - Unique group identifier
|
245
|
+
- `name` (String) - Group name (required)
|
246
|
+
- `modified_date` (String) - Last modification timestamp
|
247
|
+
- `targets` (Array) - Array of target hashes (required)
|
248
|
+
|
249
|
+
**Target Structure:**
|
250
|
+
Each target in the `targets` array should have:
|
251
|
+
|
252
|
+
- `first_name` (String) - Target's first name (required)
|
253
|
+
- `last_name` (String) - Target's last name (required)
|
254
|
+
- `email` (String) - Target's email address (required, must be valid format)
|
255
|
+
- `position` (String) - Target's job position (required)
|
256
|
+
|
257
|
+
**Instance Methods:**
|
258
|
+
|
259
|
+
- `#import_csv(csv_data)` - Import targets from CSV data
|
260
|
+
|
261
|
+
## Development
|
262
|
+
|
263
|
+
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.
|
264
|
+
|
265
|
+
### Running Tests
|
266
|
+
|
267
|
+
```bash
|
268
|
+
# Run all tests
|
269
|
+
rake spec
|
270
|
+
|
271
|
+
# Run specific test file
|
272
|
+
bundle exec rspec spec/path/to/file_spec.rb
|
273
|
+
|
274
|
+
# Run with coverage
|
275
|
+
COVERAGE=true rake spec
|
276
|
+
```
|
277
|
+
|
278
|
+
### Code Quality
|
279
|
+
|
280
|
+
```bash
|
281
|
+
# Run RuboCop linter
|
282
|
+
rake rubocop
|
283
|
+
|
284
|
+
# Auto-fix RuboCop issues
|
285
|
+
bundle exec rubocop -a
|
286
|
+
|
287
|
+
# Run all quality checks
|
288
|
+
rake # Equivalent to: rake spec rubocop
|
289
|
+
```
|
290
|
+
|
291
|
+
### Local Installation
|
292
|
+
|
293
|
+
To install this gem onto your local machine, run:
|
294
|
+
|
295
|
+
```bash
|
296
|
+
bundle exec rake install
|
297
|
+
```
|
298
|
+
|
299
|
+
### Releasing
|
300
|
+
|
301
|
+
To release a new version:
|
302
|
+
|
303
|
+
1. Update the version number in `lib/gophish/version.rb`
|
304
|
+
2. Update the `CHANGELOG.md` with the new changes
|
305
|
+
3. Run `bundle exec rake release` to create a git tag, push commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org)
|
306
|
+
|
307
|
+
## Requirements
|
308
|
+
|
309
|
+
- Ruby >= 3.1.0
|
310
|
+
- HTTParty >= 0.23.1
|
311
|
+
- ActiveSupport >= 8.0
|
312
|
+
- ActiveModel >= 8.0
|
313
|
+
- ActiveRecord >= 8.0
|
314
|
+
|
315
|
+
## Security Considerations
|
316
|
+
|
317
|
+
This gem is designed as a **defensive security tool** for authorized phishing simulations and security awareness training. Users are responsible for:
|
318
|
+
|
319
|
+
- Ensuring proper authorization before conducting phishing simulations
|
320
|
+
- Complying with applicable laws and organizational policies
|
321
|
+
- Securing API credentials and configuration data
|
322
|
+
- Using the tool only for legitimate security purposes
|
323
|
+
|
324
|
+
## Contributing
|
325
|
+
|
326
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/EliSebastian/gophish-ruby>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/EliSebastian/gophish-ruby/blob/main/CODE_OF_CONDUCT.md).
|
327
|
+
|
328
|
+
## License
|
329
|
+
|
330
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
331
|
+
|
332
|
+
## Code of Conduct
|
333
|
+
|
334
|
+
Everyone interacting in the Gophish::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/EliSebastian/gophish-ruby/blob/main/CODE_OF_CONDUCT.md).
|
335
|
+
|
336
|
+
## Support
|
337
|
+
|
338
|
+
- [GitHub Issues](https://github.com/EliSebastian/gophish-ruby/issues) - Bug reports and feature requests
|
339
|
+
- [Gophish Documentation](https://docs.getgophish.com/) - Official Gophish API documentation
|
340
|
+
- [Ruby Documentation](https://ruby-doc.org/) - Ruby language documentation
|