Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing match-replace logic #149

Merged
merged 1 commit into from
Aug 3, 2022
Merged

Fixing match-replace logic #149

merged 1 commit into from
Aug 3, 2022

Conversation

Mzack9999
Copy link
Member

@Mzack9999 Mzack9999 commented Aug 1, 2022

Proposed changes

This PR fixes #136 by overriding the original request/response properties with the DSL evaluated ones. For some weird reason, go1.18 passing a pointer of type *http.Request by reference to a nested sequence of functions causes some stack confusion, causing the original instance to be immutable.

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Example

Web Server

$ simplehttpserver -verbose
...
[2022-08-01 16:17:38]
Remote Address: 127.0.0.1:50012
GET / HTTP/1.1
Host: localhost:8000
Accept: */*
Accept-Encoding: gzip
User-Agent: firefox/7.79.1


HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Last-Modified: Fri, 17 Jun 2022 06:47:39 GMT

Proxify

$ proxify -request-match-replace-dsl "replace(request,'curl','firefox')" -v
...
HTTP Proxy Listening on 127.0.0.1:8888
Socks5 Proxy Listening on 127.0.0.1:10080
Saving traffic to logs
2022/08/01 16:17:22 [001] INFO: Got request / localhost:8888 GET /
2022/08/01 16:17:38 [002] INFO: Got request / localhost:8000 GET http://localhost:8000/
2022/08/01 16:17:38 [002] INFO: Sending request GET http://localhost:8000/
2022/08/01 16:17:38 [002] INFO: Received response 200 OK
2022/08/01 16:17:38 [002] INFO: Copying response to client 200 OK [200]
2022/08/01 16:17:38 [002] INFO: Copied 101 bytes to client error=<nil>

Curl

$ curl http://localhost:8000 -x http://localhost:8888
<pre>
<a href=".DS_Store">.DS_Store</a>
<a href="simplehttpserver.go">simplehttpserver.go</a>
</pre>

@Mzack9999 Mzack9999 added Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. Status: In Progress This issue is being worked on, and has someone assigned. labels Aug 1, 2022
@Mzack9999 Mzack9999 self-assigned this Aug 1, 2022
@Mzack9999 Mzack9999 linked an issue Aug 1, 2022 that may be closed by this pull request
@sonarcloud
Copy link

sonarcloud bot commented Aug 1, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@Mzack9999 Mzack9999 added Status: Review Needed The issue has a PR attached to it which needs to be reviewed and removed Status: In Progress This issue is being worked on, and has someone assigned. labels Aug 1, 2022
@ehsandeep ehsandeep merged commit 7a5754d into dev Aug 3, 2022
@ehsandeep ehsandeep deleted the issue-136-match-replace branch August 3, 2022 12:27
@ehsandeep ehsandeep added Status: Completed Nothing further to be done with this issue. Awaiting to be closed. and removed Status: Review Needed The issue has a PR attached to it which needs to be reviewed labels Aug 3, 2022
@ehsandeep
Copy link
Member

./proxify -request-match-replace-dsl "replace(request,'curl','**********************')" -vv -hp http://127.0.0.1:8080

                       _ ___    
   ___  _______ __ __ (_) _/_ __
  / _ \/ __/ _ \\ \ // / _/ // /
 / .__/_/  \___/_\_\/_/_/ \_, / 
/_/                      /___/	v0.0.7

		projectdiscovery.io

Use with caution. You are responsible for your actions
Developers assume no liability and are not responsible for any misuse or damage.
HTTP Proxy Listening on 127.0.0.1:8888
Socks5 Proxy Listening on 127.0.0.1:10080
Saving traffic to logs
Using upstream HTTP proxies: ["http://127.0.0.1:8080"]
2022/08/03 17:56:42 [001] INFO: Got request / google.com GET http://google.com/
GET http://google.com/ HTTP/1.1
Accept: */*
Proxy-Connection: Keep-Alive
User-Agent: **********************/7.79.1

2022/08/03 17:56:42 [001] INFO: Sending request GET http://google.com/
2022/08/03 17:56:42 [001] INFO: Received response 301 Moved Permanently
HTTP/1.1 301 Moved Permanently
Connection: close
Content-Length: 219
Cache-Control: public, max-age=2592000
Content-Type: text/html; charset=UTF-8
Date: Wed, 03 Aug 2022 12:26:42 GMT
Expires: Fri, 02 Sep 2022 12:26:42 GMT
Location: http://www.google.com/
Server: gws
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
2022/08/03 17:56:42 [001] INFO: Copying response to client 301 Moved Permanently [301]
2022/08/03 17:56:42 [001] INFO: Copied 219 bytes to client error=<nil>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Completed Nothing further to be done with this issue. Awaiting to be closed. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The request match and replace DSL functionality does not work
3 participants