Skip to content

Commit 7c908df

Browse files
committed
fix: move to format strings everywhere
1 parent c6be490 commit 7c908df

File tree

6 files changed

+46
-43
lines changed

6 files changed

+46
-43
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
*.pyc
33
__pycache__
44
*.sqlite
5+
*.sqlite-wal
6+
*.sqlite-shm
57

68
# Byte-compiled / optimized / DLL files
79
__pycache__/

api_list.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
import click
44
import requests
55

6+
67
@click.command()
7-
@click.argument('username')
8+
@click.argument("username")
89
def cmd_api_client(username):
9-
10-
r = requests.get('http://127.0.1.1:5000/api/post/{}'.format(username))
10+
r = requests.get(f"http://127.0.1.1:5000/api/post/{username}")
1111
if r.status_code != 200:
12-
click.echo('Some error ocurred. Status Code: {}'.format(r.status_code))
12+
click.echo(f"Some error ocurred. Status Code: {r.status_code}")
1313
print(r.text)
1414
return False
1515

1616
print(r.text)
1717

1818

19-
if __name__ == '__main__':
19+
if __name__ == "__main__":
2020
cmd_api_client()

api_post.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,41 @@
33
import click
44
import requests
55

6-
api_key_file = Path('/tmp/supersecret.txt')
6+
api_key_file = Path("/tmp/supersecret.txt")
7+
78

89
@click.command()
9-
@click.argument('message')
10+
@click.argument("message")
1011
def cmd_api_client(message):
1112
if not api_key_file.exists():
13+
username = click.prompt("Username")
14+
password = click.prompt("Password", hide_input=True)
1215

13-
username = click.prompt('Username')
14-
password = click.prompt('Password', hide_input=True)
15-
16-
r = requests.post('http://127.0.1.1:5000/api/key', json={'username':username, 'password':password})
16+
r = requests.post(
17+
"http://127.0.1.1:5000/api/key",
18+
json={"username": username, "password": password},
19+
)
1720

1821
if r.status_code != 200:
19-
click.echo('Invalid authentication or other error ocurred. Status code: {}'.format(r.status_code))
22+
click.echo(
23+
f"Invalid authentication or other error ocurred. Status code: {r.status_code}"
24+
)
2025
return False
2126

27+
api_key = r.json()["key"]
28+
print("Received key:", api_key)
2229

23-
api_key = r.json()['key']
24-
print('Received key:', api_key)
25-
26-
with api_key_file.open('w') as outfile:
30+
with api_key_file.open("w") as outfile:
2731
outfile.write(api_key)
2832

2933
api_key = api_key_file.open().read()
30-
r = requests.post('http://127.0.1.1:5000/api/post', json={'text':message}, headers={'X-APIKEY': api_key})
34+
r = requests.post(
35+
"http://127.0.1.1:5000/api/post",
36+
json={"text": message},
37+
headers={"X-APIKEY": api_key},
38+
)
3139
print(r.text)
3240

3341

34-
if __name__ == '__main__':
42+
if __name__ == "__main__":
3543
cmd_api_client()

brute.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
username = sys.argv[2]
88

99
passwords = [
10-
'1',
11-
'12',
12-
'123',
13-
'1234',
14-
'12345',
15-
'123456',
16-
'12345678',
17-
'123123123',
10+
"1",
11+
"12",
12+
"123",
13+
"1234",
14+
"12345",
15+
"123456",
16+
"12345678",
17+
"123123123",
1818
]
1919

2020
for password in passwords:
2121
result = subprocess.run([program, username, password], stdout=subprocess.DEVNULL)
2222
if result.returncode == 0:
23-
print("cracked! user: {} password: {}".format(username, password))
23+
print(f"cracked! user: {username} password: {password}")
2424
break

libapi.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,30 @@
66

77

88
def keygen(username, password=None):
9-
109
if password:
1110
if not libuser.login(username, password):
1211
return None
1312

1413
key = hashlib.sha256(str(random.getrandbits(2048)).encode()).hexdigest()
1514

16-
for f in Path('/tmp/').glob('vulpy.apikey.' + username + '.*'):
17-
print('removing', f)
15+
for f in Path("/tmp/").glob("vulpy.apikey." + username + ".*"):
16+
print("removing", f)
1817
f.unlink()
1918

20-
keyfile = '/tmp/vulpy.apikey.{}.{}'.format(username, key)
19+
keyfile = f"/tmp/vulpy.apikey.{username}.{key}"
2120

2221
Path(keyfile).touch()
2322

2423
return key
2524

2625

2726
def authenticate(request):
28-
if 'X-APIKEY' not in request.headers:
27+
if "X-APIKEY" not in request.headers:
2928
return None
3029

31-
key = request.headers['X-APIKEY']
30+
key = request.headers["X-APIKEY"]
3231

33-
for f in Path('/tmp/').glob('vulpy.apikey.*.' + key):
34-
return f.name.split('.')[2]
32+
for f in Path("/tmp/").glob("vulpy.apikey.*." + key):
33+
return f.name.split(".")[2]
3534

3635
return None

libuser.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ def login(username, password):
1010
print(username)
1111
print(password)
1212
user = c.execute(
13-
"SELECT * FROM users WHERE username = '{}' and password = '{}'".format(
14-
username, password
15-
)
13+
f"SELECT * FROM users WHERE username = '{username}' and password = '{password}'"
1614
).fetchone()
1715

1816
if user:
@@ -54,11 +52,7 @@ def password_change(username, password):
5452
conn.row_factory = sqlite3.Row
5553
c = conn.cursor()
5654

57-
c.execute(
58-
"UPDATE users SET password = '{}' WHERE username = '{}'".format(
59-
password, username
60-
)
61-
)
55+
c.execute(f"UPDATE users SET password = '{password}' WHERE username = '{username}'")
6256
conn.commit()
6357

6458
return True

0 commit comments

Comments
 (0)