ronin-post_ex 0.1.0.beta1

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.document +6 -0
  3. data/.github/workflows/ruby.yml +31 -0
  4. data/.gitignore +13 -0
  5. data/.rspec +1 -0
  6. data/.ruby-version +1 -0
  7. data/.yardopts +1 -0
  8. data/API_SPEC.md +235 -0
  9. data/COPYING.txt +165 -0
  10. data/ChangeLog.md +23 -0
  11. data/Gemfile +36 -0
  12. data/README.md +245 -0
  13. data/Rakefile +34 -0
  14. data/examples/bind_shell.rb +19 -0
  15. data/gemspec.yml +25 -0
  16. data/lib/ronin/post_ex/cli/shell_shell.rb +66 -0
  17. data/lib/ronin/post_ex/cli/system_shell.rb +811 -0
  18. data/lib/ronin/post_ex/remote_dir.rb +190 -0
  19. data/lib/ronin/post_ex/remote_file/stat.rb +174 -0
  20. data/lib/ronin/post_ex/remote_file.rb +417 -0
  21. data/lib/ronin/post_ex/remote_process.rb +170 -0
  22. data/lib/ronin/post_ex/resource.rb +144 -0
  23. data/lib/ronin/post_ex/sessions/bind_shell.rb +60 -0
  24. data/lib/ronin/post_ex/sessions/remote_shell_session.rb +48 -0
  25. data/lib/ronin/post_ex/sessions/reverse_shell.rb +67 -0
  26. data/lib/ronin/post_ex/sessions/rpc_session.rb +779 -0
  27. data/lib/ronin/post_ex/sessions/session.rb +73 -0
  28. data/lib/ronin/post_ex/sessions/shell_session.rb +618 -0
  29. data/lib/ronin/post_ex/system/fs.rb +650 -0
  30. data/lib/ronin/post_ex/system/process.rb +422 -0
  31. data/lib/ronin/post_ex/system/shell.rb +1037 -0
  32. data/lib/ronin/post_ex/system.rb +191 -0
  33. data/lib/ronin/post_ex/version.rb +26 -0
  34. data/lib/ronin/post_ex.rb +22 -0
  35. data/ronin-post_ex.gemspec +61 -0
  36. data/spec/sessions/bind_shell_spec.rb +31 -0
  37. data/spec/sessions/remote_shell_session_spec.rb +28 -0
  38. data/spec/sessions/reverse_shell_spec.rb +49 -0
  39. data/spec/sessions/rpc_session_spec.rb +500 -0
  40. data/spec/sessions/session_spec.rb +61 -0
  41. data/spec/sessions/shell_session_spec.rb +482 -0
  42. data/spec/spec_helper.rb +9 -0
  43. data/spec/system_spec.rb +66 -0
  44. metadata +155 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 403e9fcdbeec51db102129de41d5ab773c2f86b2befec71424ade570f0486064
4
+ data.tar.gz: a3eb7c6dbe7a4b5673b4b35bd425f384418084a17765d0a7602b63cb1eb35427
5
+ SHA512:
6
+ metadata.gz: 7e986a6e7b619c6eb56144e8c190378c8659db22c0bc71f9d91a749a26f915bd855e6447fdbe41dbea2ff73b1c21d26d1b1f93ee7cb56c000c70117858df8a12
7
+ data.tar.gz: e3ac243381c04b7f79173b3bcdff9f0afb23d1393d2d9d7b0e66d2bc5f6f75afd76a34a82102ef58378fb45220d80adbb0ff38b0c850dce58f5a6fc4641318d9
data/.document ADDED
@@ -0,0 +1,6 @@
1
+ lib/**/*.rb
2
+ -
3
+ API_SPEC.md
4
+ ChangeLog.md
5
+ COPYING.txt
6
+ man/*.md
@@ -0,0 +1,31 @@
1
+ name: CI
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ jobs:
6
+ tests:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby:
12
+ - '3.0'
13
+ - '3.1'
14
+ - '3.2'
15
+ - jruby
16
+ - truffleruby
17
+ name: Ruby ${{ matrix.ruby }}
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ - name: Install libsqlite3
25
+ run: |
26
+ sudo apt update -y && \
27
+ sudo apt install -y --no-install-recommends --no-install-suggests libsqlite3-dev
28
+ - name: Install dependencies
29
+ run: bundle install --jobs 4 --retry 3
30
+ - name: Run tests
31
+ run: bundle exec rake test
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /coverage
2
+ /doc
3
+ /pkg
4
+ /man/*.[1-9]
5
+ /vendor/bundle
6
+ /Gemfile.lock
7
+ /.bundle
8
+ /.yardoc
9
+ .DS_Store
10
+ *.db
11
+ *.log
12
+ *.swp
13
+ *~
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.1
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title 'Ronin PostEx Documentation' --protected
data/API_SPEC.md ADDED
@@ -0,0 +1,235 @@
1
+ # Post-Exploitation API Specification
2
+
3
+ ## Sys Functions
4
+
5
+ ### `sys_time -> Integer`
6
+
7
+ Gets the current time and returns the UNIX timestamp.
8
+
9
+ ### `sys_hostname -> String`
10
+
11
+ Gets the system's hostname.
12
+
13
+ ## File Functions
14
+
15
+ ### `file_open(path : String, mode : String) -> Integer`
16
+
17
+ Opens a file and returns the file-descriptor number.
18
+
19
+ ### `file_read(fd : Integer, length : Integer) -> String | nil`
20
+
21
+ Reads from an opened file-descriptor and returns the read data.
22
+ `nil` will be returned if there is no more data to be read.
23
+
24
+ ### `file_write(fd : Integer, pos : Integer, data : String) -> Integer`
25
+
26
+ Writes data to the opened file-descriptor.
27
+
28
+ ### `file_seek(fd : Integer, new_pos : Integer, whence : String)`
29
+
30
+ Seeks to a position within the file. The `whence` argument must be one of the
31
+ following strings:
32
+
33
+ * `"SEEK_SET"` - seek from beginning of file.
34
+ * `"SEEK_CUR"` - seek from current position.
35
+ * `"SEEK_END"` - seek from end of file.
36
+ * `"SEEK_DATA"` - seek to next data.
37
+ * `"SEEK_HOLE"` - seek to next hole.
38
+
39
+ ### `file_tell(fd : Integer) -> Integer`
40
+
41
+ Queries the current position within the file.
42
+
43
+ ### `file_ioctl(fd : Integer, command : String | Array[Integer], argument : Object) -> Integer`
44
+
45
+ Performs a `ioctl()` operation on the file-descriptor.
46
+
47
+ ### `file_fcntl(fd : Integer, command : String | Array[Integer], argument : Object) -> Integer`
48
+
49
+ Performs a `fcntl()` operation on the file-descriptor.
50
+
51
+ ### `file_stat(fd : Integer) => Hash[Symbol, Object] | nil`
52
+
53
+ Queries file information from the given file-descriptor and returns a Hash of
54
+ file metadata.
55
+
56
+ ### `file_close(fd : Integer)`
57
+
58
+ Closes an opened file-descriptor.
59
+
60
+ ## File-System Functions
61
+
62
+ ### `fs_getcwd() -> String`
63
+
64
+ Gets the current working directory and returns the directory path.
65
+
66
+ ### `fs_chdir(path : String)`
67
+
68
+ Changes the current working directory.
69
+
70
+ ### `fs_readfile(path : String) -> String | nil`
71
+
72
+ Reads the entire file at the given path and returns the full file's contents.
73
+
74
+ ### `fs_readlink(path : String) -> String`
75
+
76
+ Reads the destination path of a symbolic link.
77
+
78
+ ### `fs_readdir(path : String) -> Array[String]`
79
+
80
+ Reads the contents of the directory and returns an Array of directory entry
81
+ names.
82
+
83
+ ### `fs_glob(pattern : String) -> Array[String]`
84
+
85
+ Evaluates a directory glob pattern and returns all matching paths.
86
+
87
+ ### `fs_mktemp(basename : String) -> String`
88
+
89
+ Creates a temporary file with the given file basename.
90
+
91
+ ### `fs_mkdir(new_path : String)`
92
+
93
+ Creates a new directory at the given path.
94
+
95
+ ### `fs_copy(src : String, dest : String)`
96
+
97
+ Copies a source file to the destination path.
98
+
99
+ ### `fs_unlink(path : String)`
100
+
101
+ Removes a file at the given path.
102
+
103
+ ### `fs_rmdir(path : String)`
104
+
105
+ Removes an empty directory at the given path.
106
+
107
+ ### `fs_move(src : String, dest : String)`
108
+
109
+ Moves or renames a source file to a destination path.
110
+
111
+ ### `fs_link(src : String, dest : String)`
112
+
113
+ Creates a symbolic link at the destination path pointing to the source path.
114
+
115
+ ### `fs_chgrp(group : String, path : String)`
116
+
117
+ Changes the group ownership of a file or directory.
118
+
119
+ ### `fs_chown(user : String, path : String)`
120
+
121
+ Changes the user ownership of a file or directory.
122
+
123
+ ### `fs_chmod(mode : Integer, path : String)`
124
+
125
+ Changes the permissions on a file or directory.
126
+
127
+ ### `fs_stat(path : String) => Hash[Symbol, Object] | nil`
128
+
129
+ Queries file information from the given path and returns a Hash of file
130
+ metadata.
131
+
132
+ ## Process Functions
133
+
134
+ ### `process_getpid -> Integer`
135
+
136
+ Gets the current process's Process ID (PID).
137
+
138
+ ### `process_getppid -> Integer`
139
+
140
+ Gets the current process's parent Process ID (PPID).
141
+
142
+ ### `process_getuid -> Integer`
143
+
144
+ Gets the current process's user ID (UID).
145
+
146
+ ### `process_setuid(uid : Integer)`
147
+
148
+ Sets the current process's user ID (UID) to the given Integer.
149
+
150
+ ### `process_geteuid -> Integer`
151
+
152
+ Gets the current process's effective UID (EUID).
153
+
154
+ ### `process_seteuid(euid : Integer)`
155
+
156
+ Sets the current process's effective UID (EUID) to the given Integer.
157
+
158
+ ### `process_getgid -> Integer`
159
+
160
+ Gets the current process's group ID (GID).
161
+
162
+ ### `process_setgid(gid : Integer)`
163
+
164
+ Sets the current process's group ID (GID) to the given Integer.
165
+
166
+ ### `process_getegid -> Integer`
167
+
168
+ Gets the current process's effective group ID (EGID).
169
+
170
+ ### `process_setegid(egid : Integer)`
171
+
172
+ Sets the current process's effective group ID (EGID) to the given Integer.
173
+
174
+ ### `process_getsid -> Integer`
175
+
176
+ Gets the current process's session ID (SID).
177
+
178
+ ### `process_setsid(sid : Integer) -> Integer`
179
+
180
+ Sets the current process's session ID (SID).
181
+
182
+ ### `process_environ -> Hash[String, String]`
183
+
184
+ Queries all environment variables of the current process. Returns a Hash of the
185
+ env variable names and values.
186
+
187
+ ### `process_getenv(name : String) -> String | nil`
188
+
189
+ Gets an individual environment variable. If the environment variable has not
190
+ been set, `nil` will be returned.
191
+
192
+ ### `process_setenv(name : String, value : String)`
193
+
194
+ Sets an environment variable to the given value.
195
+
196
+ ### `process_unsetenv(name : String)`
197
+
198
+ Un-sets an environment variable.
199
+
200
+ ### `process_kill(pid : Integer, signal : Integer)`
201
+
202
+ Kills another process using the given Process ID (POD) and the signal number.
203
+
204
+ ### `process_popen(command : String) -> Integer`
205
+
206
+ Opens a new process using the given command string.
207
+ The file descriptor of the new process will be returned.
208
+
209
+ ### `process_read(fd : Integer, length : Integer) -> String`
210
+
211
+ Reads data from the file descriptor returned by `process_popen`.
212
+
213
+ ### `process_write(fd : Integer, data : String)`
214
+
215
+ Writes data to the file descriptor returned by `process_popen`.
216
+
217
+ ### `process_close(fd : Integer)`
218
+
219
+ Closes the file descriptor of a remote process opened via `process_popen`.
220
+
221
+ ### `process_spawn(program : String, *arguments : Array[String]) -> Integer`
222
+
223
+ Spawns a new process using the given program and additional arguments.
224
+ The process ID (PID) of the new process will be returned.
225
+
226
+ ### `process_exit`
227
+
228
+ Exits the current process.
229
+
230
+ ## Shell Functions
231
+
232
+ ### `shell_exec(command : String) -> String`
233
+
234
+ Executes the given shell command and returns it's output.
235
+
data/COPYING.txt ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/ChangeLog.md ADDED
@@ -0,0 +1,23 @@
1
+ ### 0.1.0 / 2023-XX-XX
2
+
3
+ * Initial release:
4
+ * Defines a syscall-like [API for Post-Exploitation][API Spec].
5
+ * Provides classes for interacting with the Post-Exploitation API.
6
+ * {Ronin::PostEx::System} - allows interacting with a remote system.
7
+ * {Ronin::PostEx::System::FS} - allows interacting with the file-system.
8
+ * {Ronin::PostEx::System::Process} - allows manipulating the current process
9
+ or child processes.
10
+ * {Ronin::PostEx::System::Shell} - allows interacting with an interactive
11
+ shell..
12
+ * {Ronin::PostEx::RemoteFile} - allows reading/writing files.
13
+ * {Ronin::PostEx::RemoteDir} - allows reading the contents of directories.
14
+ * {Ronin::PostEx::RemoteProcess} - allows reading/writing to an running
15
+ command.
16
+ * Supports interacting with interactive shell commands.
17
+ * Provides interactive command shells for interacting with systems.
18
+ * Supports Linux/BSD/UNIX systems.
19
+ * Provides common post-exploitation session classes for interacting with
20
+ shells, bind shells, and reverse shells.
21
+ * Supports defining custom post-exploitation session classes.
22
+
23
+ [API Spec]: https://github.com/ronin-rb/ronin-post_ex/blob/main/API_SPEC.md
data/Gemfile ADDED
@@ -0,0 +1,36 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ platform :jruby do
6
+ gem 'jruby-openssl', '~> 0.7'
7
+ end
8
+
9
+ # gem 'fake_io', '~> 0.1', github: 'postmodern/fake_io.rb',
10
+ # branch: 'main'
11
+
12
+ # gem 'command_kit', '~> 0.4', github: 'postmodern/command_kit.rb',
13
+ # branch: 'main'
14
+
15
+ # Ronin dependencies
16
+ # gem 'ronin-core', '~> 0.1', github: "ronin-rb/ronin-core",
17
+ # branch: 'main'
18
+
19
+ group :development do
20
+ gem 'rake'
21
+ gem 'rubygems-tasks', '~> 0.2'
22
+
23
+ gem 'rspec', '~> 3.0'
24
+ gem 'simplecov', '~> 0.20'
25
+
26
+ gem 'kramdown', '~> 2.0'
27
+ gem 'kramdown-man', '~> 0.1'
28
+
29
+ gem 'redcarpet', platform: :mri
30
+ gem 'yard', '~> 0.9'
31
+ gem 'yard-spellcheck', require: false
32
+
33
+ gem 'dead_end', require: false
34
+ gem 'sord', require: false, platform: :mri
35
+ gem 'stackprof', require: false, platform: :mri
36
+ end