Skip to content

Commit

Permalink
Add ronin archive command (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
moozzi authored Jan 19, 2024
1 parent aa3289d commit bbf8b3e
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Arguments:
[ARGS ...] Additional arguments for the command
Commands:
archive
asn
banner-grab
bitflip
Expand Down Expand Up @@ -877,6 +878,20 @@ Generate a [ronin-payloads] script:
$ ronin new payload my_payload.rb
```
### Archive
Archive files:
```shell
$ ronin archive -o archived.zip file.txt file2.txt
```
Archive files using tar format:
```shell
$ ronin archive -f tar -o archived.foo file1.txt file2.txt
```
### See Also
* [ronin-repos](https://github.com/ronin-rb/ronin-repos#synopsis)
Expand Down
90 changes: 90 additions & 0 deletions lib/ronin/cli/commands/archive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# frozen_string_literal: true
#
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# Ronin is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ronin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ronin. If not, see <https://www.gnu.org/licenses/>.
#

require 'ronin/cli/file_processor_command'
require 'ronin/support/archive'

module Ronin
class CLI
module Commands
#
# Archive the files.
#
# ## Usage
#
# ronin archive [option] [FILE ...]
#
# ## Options
#
# -f, --format tar|zip Archive format
# -o, --output PATH Archived file path
#
# ## Arguments
#
# FILE ... Optional file(s) to archive
#
class Archive < FileProcessorCommand

usage '[options] [FILE ...]'

option :format, short: '-f',
value: {
type: [:tar, :zip],
default: :zip
},
desc: 'Archive format'

option :output, short: '-o',
value: {
type: String,
usage: 'PATH'
},
desc: 'Archived file path'

description 'Archive the data'

man_page 'ronin-archive.1'

#
# Runs the `archive` sub-command.
#
# @param [Array<String>] files
# File arguments.
#
def run(*files)
unless options[:output]
print_error "must specify the --output option"
exit(-1)
end

unless files.empty?
Ronin::Support::Archive.send(options[:format], options[:output]) do |archive|
files.each do |file|
archive.add_file(file) do |io|
File.open(file, 'rb') do |opened_file|
io.write(opened_file.readpartial(4096)) until opened_file.eof?
end
end
end
end
end
end
end
end
end
end
40 changes: 40 additions & 0 deletions man/ronin-archive.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ronin-archive 1 "2024-01-18" Ronin "User Manuals"

## NAME

ronin-archive - Archive the files.

## SYNOPSIS

`ronin archive` [*options*] {`-o`,`--output` *PATH* } *FILE* ...

## DESCRIPTION

Archive the files.

## ARGUMENTS

*FILE*
: A file to add to the output archive.

## OPTIONS

`-f`, `--format` `tar`\|`zip`
: Archive format.

`-o`, `--output` *PATH*
: Path to the output file.

## EXAMPLES

Archive files using tar format:

$ ronin archive -f tar -o archived.tar arch1.txt arch2.txt

Archive files using zip format:

$ ronin archive -f zip -o archived.zip arch1.txt arch2.txt

## AUTHOR

Postmodern <[email protected]>
2 changes: 1 addition & 1 deletion man/ronin.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@ Postmodern <[email protected]>

## SEE ALSO

[ronin-help](ronin-help.1.md) [ronin-asn](ronin-asn.1.md) [ronin-banner-grab](ronin-banner-grab.1.md) [ronin-bitflip](ronin-bitflip.1.md) [ronin-bitsquat](ronin-bitsquat.1.md) [ronin-cert-dump](ronin-cert-dump.1.md) [ronin-cert-gen](ronin-cert-gen.1.md) [ronin-cert-grab](ronin-cert-grab.1.md) [ronin-completion](ronin-completion.1.md) [ronin-decode](ronin-decode.1.md) [ronin-decrypt](ronin-decrypt.1.md) [ronin-dns](ronin-dns.1.md) [ronin-email-addr](ronin-email-addr.1.md) [ronin-encode](ronin-encode.1.md) [ronin-encrypt](ronin-encrypt.1.md) [ronin-entropy](ronin-entropy.1.md) [ronin-escape](ronin-escape.1.md) [ronin-extract](ronin-extract.1.md) [ronin-grep](ronin-grep.1.md) [ronin-hexdump](ronin-hexdump.1.md) [ronin-highlight](ronin-highlight.1.md) [ronin-hmac](ronin-hmac.1.md) [ronin-homoglyph](ronin-homoglyph.1.md) [ronin-host](ronin-host.1.md) [ronin-http](ronin-http.1.md) [ronin-ip](ronin-ip.1.md) [ronin-iprange](ronin-iprange.1.md) [ronin-irb](ronin-irb.1.md) [ronin-md5](ronin-md5.1.md) [ronin-netcat](ronin-netcat.1.md) [ronin-new](ronin-new.1.md) [ronin-pack](ronin-pack.1.md) [ronin-proxy](ronin-proxy.1.md) [ronin-public-suffix-list](ronin-public-suffix-list.1.md) [ronin-quote](ronin-quote.1.md) [ronin-rot](ronin-rot.1.md) [ronin-sha1](ronin-sha1.1.md) [ronin-sha256](ronin-sha256.1.md) [ronin-sha512](ronin-sha512.1.md) [ronin-strings](ronin-strings.1.md) [ronin-tips](ronin-tips.1.md) [ronin-tld-list](ronin-tld-list.1.md) [ronin-typo](ronin-typo.1.md) [ronin-typosquat](ronin-typosquat.1.md) [ronin-unescape](ronin-unescape.1.md) [ronin-unhexdump](ronin-unhexdump.1.md) [ronin-unpack](ronin-unpack.1.md) [ronin-unquote](ronin-unquote.1.md) [ronin-url](ronin-url.1.md) [ronin-xor](ronin-xor.1.md)
[ronin-help](ronin-help.1.md) [ronin-archive](ronin-archive.1.md) [ronin-asn](ronin-asn.1.md) [ronin-banner-grab](ronin-banner-grab.1.md) [ronin-bitflip](ronin-bitflip.1.md) [ronin-bitsquat](ronin-bitsquat.1.md) [ronin-cert-dump](ronin-cert-dump.1.md) [ronin-cert-gen](ronin-cert-gen.1.md) [ronin-cert-grab](ronin-cert-grab.1.md) [ronin-completion](ronin-completion.1.md) [ronin-decode](ronin-decode.1.md) [ronin-decrypt](ronin-decrypt.1.md) [ronin-dns](ronin-dns.1.md) [ronin-email-addr](ronin-email-addr.1.md) [ronin-encode](ronin-encode.1.md) [ronin-encrypt](ronin-encrypt.1.md) [ronin-entropy](ronin-entropy.1.md) [ronin-escape](ronin-escape.1.md) [ronin-extract](ronin-extract.1.md) [ronin-grep](ronin-grep.1.md) [ronin-hexdump](ronin-hexdump.1.md) [ronin-highlight](ronin-highlight.1.md) [ronin-hmac](ronin-hmac.1.md) [ronin-homoglyph](ronin-homoglyph.1.md) [ronin-host](ronin-host.1.md) [ronin-http](ronin-http.1.md) [ronin-ip](ronin-ip.1.md) [ronin-iprange](ronin-iprange.1.md) [ronin-irb](ronin-irb.1.md) [ronin-md5](ronin-md5.1.md) [ronin-netcat](ronin-netcat.1.md) [ronin-new](ronin-new.1.md) [ronin-pack](ronin-pack.1.md) [ronin-proxy](ronin-proxy.1.md) [ronin-public-suffix-list](ronin-public-suffix-list.1.md) [ronin-quote](ronin-quote.1.md) [ronin-rot](ronin-rot.1.md) [ronin-sha1](ronin-sha1.1.md) [ronin-sha256](ronin-sha256.1.md) [ronin-sha512](ronin-sha512.1.md) [ronin-strings](ronin-strings.1.md) [ronin-tips](ronin-tips.1.md) [ronin-tld-list](ronin-tld-list.1.md) [ronin-typo](ronin-typo.1.md) [ronin-typosquat](ronin-typosquat.1.md) [ronin-unescape](ronin-unescape.1.md) [ronin-unhexdump](ronin-unhexdump.1.md) [ronin-unpack](ronin-unpack.1.md) [ronin-unquote](ronin-unquote.1.md) [ronin-url](ronin-url.1.md) [ronin-xor](ronin-xor.1.md)
7 changes: 7 additions & 0 deletions spec/cli/commands/archive_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'
require 'ronin/cli/commands/archive'
require_relative 'man_page_example'

describe Ronin::CLI::Commands::Archive do
include_examples "man_page"
end

0 comments on commit bbf8b3e

Please sign in to comment.