Skip to content

Commit a6fc8c5

Browse files
authored
Add HTTP Sender script to RSA sign the requests (#429)
* Create RsaSigningForZap.py Signed-off-by: Michał Walkowski <mi.walkowski@gmail.com>
1 parent 9b69ac6 commit a6fc8c5

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this add-on will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## [Unreleased]
7+
### Added
8+
- httpsender/RsaSigningForZap.py - A script that signs requests using RSA
9+
710
### Changed
811
- Update minimum ZAP version to 2.14.0.
912
- Remove checks for CFU initiator in HTTP Sender scripts and docs, no longer needed.

httpsender/RsaSigningForZap.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# RSA Signing Script for Zed Attack Proxy - ZAP
2+
# HelpAddOn Script - HTTPSender
3+
# Michal Walkowski - https://mwalkowski.github.io/
4+
# https://github.com/mwalkowski
5+
#
6+
# Tested with Jython 14 beta and ZAP 2.14.0
7+
# For RSA Signing Process: https://httpwg.org/http-extensions/draft-ietf-httpbis-message-signatures.html#name-rsassa-pkcs1-v1_5-using-sha
8+
# Based On: https://mwalkowski.github.io/post/using-burp-python-scripts-to-sign-requests-with-rsa-keys/
9+
10+
import urlparse
11+
import uuid
12+
import datetime
13+
import base64
14+
import subprocess
15+
16+
# path to private.key
17+
PRIVATE_KEY = "private.key"
18+
SIGNATURE_HEADER = 'X-Signature'
19+
NONCE_HEADER = 'X-Nonce-Value'
20+
NONCE_CREATED_AT_HEADER = 'X-Nonce-Created-At'
21+
22+
23+
def sign(signature_input):
24+
print('signature_input', signature_input)
25+
signature_input_b64 = base64.standard_b64encode(signature_input.encode()).decode()
26+
print('signature_input_b64', signature_input_b64)
27+
28+
cmd = """printf %s "{}" | openssl dgst -sha256 -sign {}| openssl base64""".format(signature_input_b64, PRIVATE_KEY)
29+
print(cmd)
30+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
31+
32+
output, err = process.communicate()
33+
if err.decode() != "":
34+
raise Exception(err)
35+
36+
return output.decode().replace("\n", "")
37+
38+
def sendingRequest(msg, initiator, helper):
39+
method = msg.getRequestHeader().getMethod()
40+
path = urlparse.urlparse(msg.getRequestHeader().getURI().toString()).path
41+
body = msg.getRequestBody().toString()
42+
print(msg.getRequestBody().toString())
43+
44+
nonce_value = str(uuid.uuid4())
45+
nonce_created_at = '{}+00:00'.format(datetime.datetime.utcnow().isoformat())
46+
signature = sign("{}{}{}{}{}".format(method, path, nonce_value, nonce_created_at, body))
47+
48+
print('Adding new {}: {}'.format(SIGNATURE_HEADER, signature))
49+
msg.getRequestHeader().setHeader(SIGNATURE_HEADER, signature)
50+
51+
print('Adding new {}: {}'.format(NONCE_HEADER, nonce_value))
52+
msg.getRequestHeader().setHeader(NONCE_HEADER, nonce_value)
53+
54+
print('Adding new {}: {}'.format(NONCE_CREATED_AT_HEADER, nonce_created_at))
55+
msg.getRequestHeader().setHeader(NONCE_CREATED_AT_HEADER, nonce_created_at)
56+
57+
58+
def responseReceived(msg, initiator, helper):
59+
pass

0 commit comments

Comments
 (0)