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

returning template as bytes according to twisted.web.resource.render #82

Merged
merged 6 commits into from
Dec 31, 2024

Conversation

italovalcy
Copy link

@italovalcy italovalcy commented Dec 30, 2024

Fix #81

Description of the change

  • This pull request changes the return format of honeypots.helper.load_template from string to bytes, as expected by twisted.web.resource.render()
  • I also took the opportunity to fix some unrelated linter errors and add a OS dependency install step due to build errors on python 3.8.

Local tests

After the change I was able to load the page as expected following the steps below:

  1. Start honeypots with the proposed change:
python3 -m honeypots --termination-strategy input --setup http --port 80
  1. Run a test using curl:
# curl -v http://172.16.50.1
*   Trying 172.16.50.1:80...
* Connected to 172.16.50.1 (172.16.50.1) port 80 (#0)
> GET / HTTP/1.1
> Host: 172.16.50.1
> User-Agent: curl/7.88.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Mon, 30 Dec 2024 12:52:44 GMT
< Server: cloudflare
< Content-Type: text/html; charset=utf-8
< Content-Length: 1101
< 
<!DOCTYPE html>
<html>
        <head>
                <link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css' />
                <link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' />
                <meta http-equiv='content-type' content='text/html;charset=utf-8' />
                <title>Login</title>
                <style>body,html {height: 100%;}</style>
        </head>
        <body>
                <div class='container-fluid h-100'>
                        <div class='row justify-content-center h-100 align-items-center'>
                        <div class='col col-xl-3'>
                                <form id='login' action='' method='post'>
                                        <div class='form-group'>
                                                <input class='form-control form-control-sm' name='username' type='text' placeholder='username' id='username'>
                                        </div>
                                        <div class='form-group'>
                                                <input class='form-control form-control-sm' name='password' type='password' placeholder='password' id='password'>
                                        </div>
                                        <div class='form-group'>
                                                <button class='btn btn-default btn-sm btn-block' type='submit'>login</button>
                                        </div>
                                </form>
                        </div>
                        </div>
                </div>
        </body>
</html>
* Connection #0 to host 172.16.50.1 left intact

Unit tests:

git clone https://github.com/qeeqbox/honeypots
cd honeypots/
python3 -m venv venv
source venv/bin/activate
curl -LO https://github.com/qeeqbox/honeypots/pull/82.diff
patch -p1  < 82.diff
python3 -m pytest
...
==== 31 passed, 8 warnings in 22.31s =====

@italovalcy italovalcy changed the title returning template as bytes as expected by twisted.web.resource.render returning template as bytes according to twisted.web.resource.render Dec 30, 2024
@italovalcy italovalcy marked this pull request as ready for review December 30, 2024 16:35
@giga-a giga-a merged commit 538390c into qeeqbox:main Dec 31, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http and https honeypots are returning error 500
2 participants