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

Sourcery refactored master branch #4

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 2proc_pmutex.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def enter_region(process):
other = 1 - process
interested[process] = True
turn = process
while turn == process and interested[other] == True:
while turn == turn and interested[other] == True:
k += 1
# if (k % 10000 == 0):
# print "process wait",process
continue
print("entered_critical: %d ticks %d" % (process, k))
print("entered_critical: %d ticks %d" % (turn, k))
Comment on lines -18 to +23
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function enter_region refactored with the following changes:



def leave_region(process):
Expand Down
2 changes: 1 addition & 1 deletion CVE-2016-2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
ssl_sock.write("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
print("sent...")
try:
print("recv:" + ssl_sock.recv(512))
print(f"recv:{ssl_sock.recv(512)}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 33-33 refactored with the following changes:

except ssl.SSLError as err:
if err.find("record overflow"):
print("Vulnerable")
Expand Down
4 changes: 1 addition & 3 deletions CVE-2017-7679.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def check_url(url, buff=None):
s1 = check_url(sys.argv[1])
s2 = check_url(sys.argv[1], buff)

i = list(difflib.unified_diff(s1, s2))

if len(i) > 0:
if i := list(difflib.unified_diff(s1, s2)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 34-36 refactored with the following changes:

print("[+] Host Vulnerable!")
else:
print("[-] Host Not vulnerable!")
6 changes: 3 additions & 3 deletions TOTP_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

tmp = tempfile.mkstemp()[1]

os.system("cat %s | gpg --decrypt > %s" % (sys.argv[1], tmp))
os.system(f"cat {sys.argv[1]} | gpg --decrypt > {tmp}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 15-25 refactored with the following changes:


conn = sqlite3.connect(tmp)
c = conn.cursor()
Expand All @@ -21,5 +21,5 @@
totp = pyotp.TOTP(row[2])
print(totp.now(), row[1])

os.system("shred %s -v" % tmp)
os.system("rm %s" % tmp)
os.system(f"shred {tmp} -v")
os.system(f"rm {tmp}")
10 changes: 5 additions & 5 deletions android_fde_decryptkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
ENCRYPT = 1
DECRYPT = 0

assert path.isfile(header_file), "Input file '%s' not found." % header_file
assert path.isfile(encrypted_partition), (
"Input file '%s' not found." % encrypted_partition
)
assert path.isfile(header_file), f"Input file '{header_file}' not found."
assert path.isfile(
encrypted_partition
), f"Input file '{encrypted_partition}' not found."
Comment on lines -36 to +39
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 36-55 refactored with the following changes:

header = open(header_file, "rb").read()

# Unpack header
Expand All @@ -52,7 +52,7 @@
fsSize2,
failedDecrypt,
cryptoType,
) = struct.unpack(HEADER_FORMAT, header[0:100])
) = struct.unpack(HEADER_FORMAT, header[:100])

encrypted_key = header[ftrSize : ftrSize + keySize]
salt = header[ftrSize + keySize + 32 : ftrSize + keySize + 32 + 16]
Expand Down
2 changes: 1 addition & 1 deletion bitnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def make_request(*args):
opener = urllib.request.build_opener()
opener.addheaders = [("User-agent", "Mozilla/5.0" + str(random.randrange(1000000)))]
opener.addheaders = [("User-agent", f"Mozilla/5.0{random.randrange(1000000)}")]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function make_request refactored with the following changes:

try:
return opener.open(*args).read().strip()
except Exception as e:
Expand Down
6 changes: 1 addition & 5 deletions brainflayer_parallelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
outputfile = sys.argv[2]
h = sys.argv[1]

cmd = (
"%s -b %s -m %s -f %s -v -a -o %s -I"
% (binary, bloomfile, tabfile, binfile, outputfile)
+ " %s"
)
cmd = f"{binary} -b {bloomfile} -m {tabfile} -f {binfile} -v -a -o {outputfile} -I %s"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 15-19 refactored with the following changes:


n = 10
for i in range(1, n + 1):
Expand Down
4 changes: 2 additions & 2 deletions check_nmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def main():
nm.scan(host, sys.argv[2], arguments="--system-dns")
ports = getports(nm, host)
num_status, output = proc_results(nm, old_nm, host, ports)
json2file(".check_nmap.py." + host + ".cache", nm[host])
print(status[num_status] + ": " + output)
json2file(f".check_nmap.py.{host}.cache", nm[host])
print(f"{status[num_status]}: {output}")
Comment on lines -97 to +98
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

sys.exit(num_status)


Expand Down
2 changes: 1 addition & 1 deletion compression_test2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test(msg_data):
a, b, c = struct.unpack(">4si{0:d}s".format(msg_len), msg_data)
print("Pack:", a, b, c.encode("hex"))
new_data = zlib.decompress(c)
print("Decompressed data: " + new_data)
print(f"Decompressed data: {new_data}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test refactored with the following changes:



test("dario")
19 changes: 9 additions & 10 deletions crack_AES256.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ def Hash(x):


def pw_decode(s, password):
if password is not None:
secret = Hash(password)
try:
d = DecodeAES(secret, s)
# d = decrypt(s,secret)
except Exception as e:
raise Exception("Invalid password")
return d
else:
if password is None:
return s
secret = Hash(password)
try:
d = DecodeAES(secret, s)
# d = decrypt(s,secret)
except Exception as e:
raise Exception("Invalid password")
return d
Comment on lines -32 to +40
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pw_decode refactored with the following changes:



def try_pw(encoded_seed, pw_cand):
Expand Down Expand Up @@ -174,7 +173,7 @@ def test():

seed = try_pw(encoded_seed, pw_cand1)
if chk_seed(seed):
print("pw is good: %s" % pw_cand1)
print(f"pw is good: {pw_cand1}")
Comment on lines -177 to +176
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test refactored with the following changes:

print(seed)
cnt_good += 1
break
Expand Down
4 changes: 1 addition & 3 deletions crc_make_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def make_crc_table(const):


def displaytable(table):
string_hex_line = ""
for i in numbers:
string_hex_line += hex(i)
string_hex_line = "".join(hex(i) for i in numbers)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function displaytable refactored with the following changes:

  • Use str.join() instead of for loop (use-join)

print(string_hex_line)


Expand Down
2 changes: 1 addition & 1 deletion docker-get-swarm-nodes-ips.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import docker
import sys

client = docker.DockerClient(base_url="tcp://%s:2375" % sys.argv[1])
client = docker.DockerClient(base_url=f"tcp://{sys.argv[1]}:2375")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 4-4 refactored with the following changes:


nodes = client.nodes.list()
for node in nodes:
Expand Down
2 changes: 1 addition & 1 deletion ecdsa_privtopub.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def leftmost_bit(x):
assert x > 0
result = 1
while result <= x:
result = 2 * result
result *= 2
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Point.__mul__ refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)

return result / 2

e = other
Expand Down
2 changes: 1 addition & 1 deletion exo2mp4.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@

for key, value in sorted(parts):
print(key, value)
system("cat %s >> %s" % (value, target))
system(f"cat {value} >> {target}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 24-24 refactored with the following changes:

2 changes: 1 addition & 1 deletion ftpmassuploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def upload(ip, filename):
if run:
ftp = FTP(ip, USER, PASS, timeout=timeout)
# tp.login()
ftp.storlines("STOR %s" % filename, open(filename, "r"))
ftp.storlines(f"STOR {filename}", open(filename, "r"))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function upload refactored with the following changes:



filename = sys.argv[1]
Expand Down
3 changes: 1 addition & 2 deletions hashtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
print("Algo\tSpeed")

a = list(hashlib.algorithms_available)
a.append("sha3_256")
a.append("sha3_512")
a.extend(("sha3_256", "sha3_512"))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 10-11 refactored with the following changes:


for h in a:
size = 100
Expand Down
22 changes: 6 additions & 16 deletions imm_pasadas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,18 @@

url_base = "http://www.montevideo.gub.uy/transporteRest/"

if l > 4:
url = (
url_base
+ "pasadas/"
+ str(codigo_parada)
+ "/"
+ tipo_dia
+ "/"
+ str(linea)
+ "/"
+ hora
)
else:
url = url_base + "pasadas/" + str(codigo_parada) + "/" + tipo_dia + "/" + hora

url = (
f"{url_base}pasadas/{str(codigo_parada)}/{tipo_dia}/{str(linea)}/{hora}"
if l > 4
else f"{url_base}pasadas/{str(codigo_parada)}/{tipo_dia}/{hora}"
)
j = json.loads(urllib.request.urlopen(url).read())
for pasada in j:
print(
"Linea:",
pasada["linea"],
"Hora:",
str(pasada["horaDesc"]),
pasada["horaDesc"],
Comment on lines -21 to +32
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 21-42 refactored with the following changes:

"Destino:",
pasada["destino"],
)
2 changes: 1 addition & 1 deletion licencia.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def calculate_best_candidate(start_date, days, franqueo):
last_best = 0
hs = init_holidays(dstart.year)
best = []
for i in range(0, 365):
for _ in range(0, 365):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calculate_best_candidate refactored with the following changes:

# dstart += timedelta(days=1)

r, d = lic(dstart, days, franqueo, hs)
Expand Down
2 changes: 1 addition & 1 deletion logsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def seeklog(A, key, imin, imax):


def test():
tmp = [x for x in range(1024 * 1024 * 20)]
tmp = list(range(1024 * 1024 * 20))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test refactored with the following changes:

print("res=", seeklog(tmp, 1337, 0, len(tmp)))
print("count=", count)

Expand Down
12 changes: 6 additions & 6 deletions lrutest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ def test():
lru = LRU(4)

for i in range(0, 21):
lru.insert("key" + str(i), str(i))
lru.insert(f"key{str(i)}", str(i))

for i in range(0, 1000):
for _ in range(0, 1000):
lru.get("key13")
for i in range(0, 500):
for _ in range(0, 500):
lru.get("key11")
for i in range(0, 250):
for _ in range(0, 250):
lru.get("key7")
for i in range(0, 125):
for _ in range(0, 125):
lru.get("key5")
lru.get("key3")
lru.get("key2")
lru.get("key1")

print(lru.access)
for i in range(0, 3):
for _ in range(0, 3):
Comment on lines -47 to +62
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test refactored with the following changes:

lru.purge()
print(lru.access)

Expand Down
2 changes: 1 addition & 1 deletion mmapread.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
pid = int(sys.argv[1])
with open("/proc/%d/maps" % pid, "r") as maps_file:
with open("/proc/%d/mem" % pid, "r", 0) as mem_file:
for line in maps_file.readlines():
for line in maps_file:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 11-11 refactored with the following changes:

line = line.rstrip()
cols = line.split(" ")
print(cols)
Expand Down
15 changes: 4 additions & 11 deletions msfhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@
local_host = lhost[0]
local_port = lhost[1]

if opt == "-n":
remote_hosts = list(ipaddress.IPv4Network(str(sys.argv[2]), strict=False).hosts())

if opt == "-f":
remote_hosts = []
fp = open(sys.argv[2], "r")
for line in fp:
if line.find("#") == -1:
remote_hosts.append(line.strip())
remote_hosts = [line.strip() for line in fp if line.find("#") == -1]
elif opt == "-n":
remote_hosts = list(ipaddress.IPv4Network(str(sys.argv[2]), strict=False).hosts())

for remote_host in remote_hosts:
if no_ping:
if not no_ping and pyping.ping(str(remote_host)) or no_ping:
print(payload % (exploit, remote_host, local_host, local_port, meterpreter))
else:
if pyping.ping(str(remote_host)):
print(payload % (exploit, remote_host, local_host, local_port, meterpreter))
Comment on lines -30 to -45
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 30-45 refactored with the following changes:

print("exit")
3 changes: 1 addition & 2 deletions originstamp_privkey_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def get_json(fp, sha256s):


for line in fileinput.input():
data = get_json(fp, line.replace("\n", ""))
if data:
if data := get_json(fp, line.replace("\n", "")):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 31-32 refactored with the following changes:

print(data["blockchain_transaction"]["private_key"])

fp.close()
22 changes: 8 additions & 14 deletions pmkid_test_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,20 @@ def PMKID(apmac, clmac, PSK, SSID):


REQ = "2a416a999af0a6bf454684269afb06ef"
print("Required hash: %s" % REQ)
print(f"Required hash: {REQ}")
apmac = "34:bf:90:4a:bb:57"
clmac = "98:de:d0:1a:97:c2"
PSK = "786 5555"
SSID = "unknown"

print("SSID: [%s]" % SSID)
print("PSK: [%s]" % PSK)
print("AP mac: %s" % apmac)
print("Cl mac: %s" % clmac)
print(f"SSID: [{SSID}]")
print(f"PSK: [{PSK}]")
print(f"AP mac: {apmac}")
print(f"Cl mac: {clmac}")
print(
"HASH: %s*%s*%s*%s"
% (
REQ,
apmac.replace(":", ""),
clmac.replace(":", ""),
binascii.hexlify(SSID),
)
f'HASH: {REQ}*{apmac.replace(":", "")}*{clmac.replace(":", "")}*{binascii.hexlify(SSID)}'
)

pmkid, pmk = PMKID(apmac, clmac, PSK, SSID)
print("PMK: " + binascii.hexlify(pmk))
print("PMKID: " + binascii.hexlify(pmkid[0:32]))
print(f"PMK: {binascii.hexlify(pmk)}")
print(f"PMKID: {binascii.hexlify(pmkid[:32])}")
Comment on lines -14 to +30
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 14-36 refactored with the following changes:

Loading
Loading