|
1
|
|
|
#!/usr/bin/env python3 |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
|
|
4
|
|
|
"""Generic file checksum request.""" |
|
5
|
|
|
|
|
6
|
|
|
import json |
|
7
|
|
|
from collections import OrderedDict |
|
8
|
|
|
|
|
9
|
|
|
from .. import credentials |
|
10
|
|
|
from .tclrequest import TclRequest |
|
11
|
|
|
from .tclresult import ChecksumResult |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class ChecksumRequest(TclRequest): |
|
|
|
|
|
|
15
|
|
|
"""Generic file checksum request.""" |
|
16
|
|
|
|
|
17
|
|
|
def __init__(self, address, file_uri): |
|
18
|
|
|
"""Populate variables.""" |
|
19
|
|
|
super().__init__() |
|
20
|
|
|
# NOTE: THIS HAS TO BE RUN ON AN ENCSLAVE |
|
21
|
|
|
self.uri = "/checksum.php" |
|
22
|
|
|
self.method = "POST" |
|
23
|
|
|
self.address = address |
|
24
|
|
|
self.file_uri = file_uri |
|
25
|
|
|
|
|
26
|
|
|
def get_headers(self): |
|
27
|
|
|
"""Return request headers.""" |
|
28
|
|
|
return {"User-Agent": "tcl"} |
|
29
|
|
|
|
|
30
|
|
|
def get_params(self): |
|
31
|
|
|
"""Return request parameters.""" |
|
32
|
|
|
params = OrderedDict() |
|
33
|
|
|
params.update(credentials.get_creds2()) |
|
34
|
|
|
payload = {self.address: self.file_uri} |
|
35
|
|
|
payload_json = json.dumps(payload) |
|
36
|
|
|
params["address"] = bytes(payload_json, "utf-8") |
|
37
|
|
|
return params |
|
38
|
|
|
|
|
39
|
|
|
def is_done(self, http_status: int, contents: str) -> bool: |
|
40
|
|
|
"""Handle request result.""" |
|
41
|
|
|
if http_status == 200: |
|
42
|
|
|
# <ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER> means ERROR (invalid ADDRESS!) |
|
43
|
|
|
if "<ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER>" in contents: |
|
44
|
|
|
self.error = "INVALID URI: {}".format(self.file_uri) |
|
45
|
|
|
self.success = False |
|
46
|
|
|
return True |
|
47
|
|
|
self.response = contents |
|
48
|
|
|
self.result = ChecksumResult(contents) |
|
49
|
|
|
self.success = True |
|
50
|
|
|
return True |
|
51
|
|
|
self.error = "HTTP {}".format(http_status) |
|
52
|
|
|
self.success = False |
|
53
|
|
|
return True |
|
54
|
|
|
|