Skip to content

Commit

Permalink
Added --output/--output-format to ronin-listener http (closes #5).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jul 4, 2023
1 parent bb5f991 commit 0293562
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/ronin/listener/cli/commands/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#

require 'ronin/listener/cli/command'
require 'ronin/listener/output_formats'
require 'ronin/listener/http'

require 'ronin/core/cli/logging'
Expand All @@ -36,6 +37,9 @@ module Commands
#
# ## Options
#
# -o, --output FILE The output file to write HTTP requests to
# -F, --output-format txt|csv|json|ndjson
# The output format
# -H, --host IP The interface to listen on (Default: 0.0.0.0)
# -p, --port PORT The port to listen on (Default: 8080)
# --vhost HOST The Host: header to filter requests by
Expand All @@ -53,6 +57,22 @@ class Http < Command

usage '[options]'

option :output, short: '-o',
value: {
type: String,
usage: 'FILE'
},
desc: 'The output file to write HTTP requests to' do |path|
options[:output] = path
options[:output_format] ||= OutputFormats.infer_from(path)
end

option :output_format, short: '-F',
value: {
type: OutputFormats.formats
},
desc: 'The output format'

option :host, short: '-H',
value: {
type: String,
Expand Down Expand Up @@ -96,6 +116,10 @@ class Http < Command
# Runs the `ronin-listener http` command.
#
def run
output_file = if options[:output] && options[:output_format]
options[:output_format].open(options[:output])
end

Ronin::Listener::HTTP.listen(**server_kwargs) do |request|
remote_addr = request.remote_address

Expand All @@ -109,6 +133,8 @@ def run

puts request.body if request.body
puts

output_file << request if output_file
end
end

Expand Down
8 changes: 8 additions & 0 deletions man/ronin-listener-http.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ Starts a HTTP server for receiving exfiltrated data.

## OPTIONS

`-o`, `--output` *FILE*
The output file to write the received DNS queries to.

`-F`, `--output-format` `txt`|`csv`|`json`|`ndjson`
The output format to use. If not specified, the output format will be inferred
from the output file's extension. If the output format cannot be inferred from
the output file's extension, then it will default to `txt` format.

`-H`, `--host` *IP*
The interface to listen on. Defaults to `0.0.0.0` if not given.

Expand Down

0 comments on commit 0293562

Please sign in to comment.