Skip to content

Commit 87dce81

Browse files
authored
Merge pull request #319 from thc202/fix-curl-file
Prevent and warn on curl file inclusion
2 parents 50a0377 + d9f00db commit 87dce81

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1616

1717
### Fixed
1818
- active/User defined attacks.js - correctly escape dot character in some evidence strings.
19+
- targeted/curl_command_generator.js - prevent and warn on local file inclusion when generating the command.
20+
Thanks to James Kettle (@albinowax) for reporting.
1921

2022
## [15] - 2022-10-02
2123
### Added

targeted/curl_command_generator.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,36 @@ function invokeWith(msg) {
77
var string = "curl -i -s -k -X '"+msg.getRequestHeader().getMethod()+"' \\\n";
88
var header = msg.getRequestHeader().getHeadersAsString();
99
header = header.split(msg.getRequestHeader().getLineDelimiter());
10+
var suspiciousHeaders = false;
1011
for(var i=0;i<header.length;i++){
12+
var headerEntry = header[i].trim()
13+
if (headerEntry.startsWith("@")) {
14+
suspiciousHeaders = true;
15+
}
1116
//blacklisting Host (other blacklisting should also specify here
12-
var keyval = header[i].split(":");
17+
var keyval = headerEntry.split(":");
1318
if(keyval[0].trim() != "Host")
14-
string += " -H '"+header[i].trim()+"' ";
19+
string += " -H '"+headerEntry+"' ";
1520
}
1621
string += " \\\n";
1722
var body = msg.getRequestBody().toString();
1823
if(body.length() != 0){
19-
string += "--data-binary $'"+addSlashes(body)+"' \\\n";
24+
string += "--data-raw $'"+addSlashes(body)+"' \\\n";
2025
}
2126
string += "'"+msg.getRequestHeader().getURI().toString()+"'";
22-
var selected = new java.awt.datatransfer.StringSelection(string);
23-
var clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
24-
clipboard.setContents(selected,null);
27+
28+
if (!suspiciousHeaders) {
29+
var selected = new java.awt.datatransfer.StringSelection(string);
30+
var clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
31+
clipboard.setContents(selected,null);
32+
}
2533
print (string);
34+
35+
if (suspiciousHeaders) {
36+
print("\n**WARNING**");
37+
print("The generated command might be including a local file (e.g. `@/path/to/file`) in a header, carefully review the command before executing it.");
38+
print("Note: The command was *not* added to the clipboard.\n");
39+
}
2640
}
2741

2842
function addSlashes(body){

0 commit comments

Comments
 (0)