proskater123 Posted June 8, 2013 Share Posted June 8, 2013 So I found this script to decrypt a netgear cfg file. But when i try to run the script it comes up with a bunch of errors. Can someone look at the script and possibly fix the issues? I know nothing about python. import pyDes import os, sys # Encryption key is a slightly variation of "NtgrBak" KEY = [0x56-8, 0x74, 0x67, 0x72, 0x42, 0x61, 0x6b, 0x00] def derive_des_key(ascii_key): def extract_by_offset(offset): byte_index = offset >> 3 bit_index = byte_index << 3 v0 = (ascii_key[byte_index] << 8) | ascii_key[byte_index+1] v1 = 8 - (offset - bit_index) v0 >>= v1 return v0 & 0xfe k = "" for i in range(0, 7*8, 7): k += chr(extract_by_offset(i)) return k def decrypt_block(block, key_bytes): k = derive_des_key(key_bytes) des = pyDes.des(k, pyDes.ECB) r = des.decrypt(block) return r def main(): data = sys.stdin.read() assert (len(data) % 8) == 0 current_key = KEY[:] r = "" for i in range(0, len(data), 8): current_key[0] += 8 if current_key[0] > 0xff: current_key[0] = current_key[0] - 0x100 current_key[1] += 1 block = data[i:i+8] d = decrypt_block(block, current_key) r += d sys.stdout.write(r) Quote Link to comment Share on other sites More sharing options...
newbi3 Posted June 8, 2013 Share Posted June 8, 2013 Can you post the errors please? Quote Link to comment Share on other sites More sharing options...
proskater123 Posted June 8, 2013 Author Share Posted June 8, 2013 I took out the <cut> and </cut> cause I do beileve that they are not needed. Then when I run the script in windows C:/python puthonscript.py File "pythonscript.py", Line 8 Def extract_by_offset(offset): /\ IndentationError: expected an indent block Quote Link to comment Share on other sites More sharing options...
Mr-Protocol Posted June 8, 2013 Share Posted June 8, 2013 It also helps if you put the script in code brackets, but based off that error, it seems you have an indenting issue. Python uses indents to break out functions, and other languages like C use {}. But python only uses indents so you have to watch your spacing. (I am not well versed in Python, but I know a little bit) Quote Link to comment Share on other sites More sharing options...
proskater123 Posted June 8, 2013 Author Share Posted June 8, 2013 Thats my problem as well. I have no idea how to work with python. Thats why I am here :( Quote Link to comment Share on other sites More sharing options...
Mr-Protocol Posted June 8, 2013 Share Posted June 8, 2013 http://mail.python.org/pipermail/tutor/2007-January/051903.html Quote Link to comment Share on other sites More sharing options...
proskater123 Posted June 8, 2013 Author Share Posted June 8, 2013 Hey thanks that kinda helped. Lets see if i understand what it said Quote Link to comment Share on other sites More sharing options...
Sebkinne Posted June 8, 2013 Share Posted June 8, 2013 It seems to me like you have no indentation at all. Make sure to format into the correct code blocks and it will run. Quote Link to comment Share on other sites More sharing options...
digip Posted June 8, 2013 Share Posted June 8, 2013 (edited) Also, doesn't the top of the script need to be defined? Like bash shell scripts? #!/usr/local/bin/python # change above line to point to local # python executable or #!/usr/bin/env python import pyDes import os, sys ## Encryption key is a slightly variation of "NtgrBak" KEY = [0x56-8, 0x74, 0x67, 0x72, 0x42, 0x61, 0x6b, 0x00] def derive_des_key(ascii_key): def extract_by_offset(offset): byte_index = offset >> 3 bit_index = byte_index << 3 v0 = (ascii_key[byte_index] << 8) | ascii_key[byte_index+1] v1 = 8 - (offset - bit_index) v0 >>= v1 return v0 & 0xfe k = "" for i in range(0, 7*8, 7): k += chr(extract_by_offset(i)) return k def decrypt_block(block, key_bytes): k = derive_des_key(key_bytes) des = pyDes.des(k, pyDes.ECB) r = des.decrypt(block) return r def main(): data = sys.stdin.read() assert (len(data) % 8) == 0 current_key = KEY[:] r = "" for i in range(0, len(data), 8): current_key[0] += 8 if current_key[0] > 0xff: current_key[0] = current_key[0] - 0x100 current_key[1] += 1 block = data[i:i+8] d = decrypt_block(block, current_key) r += d sys.stdout.write(r) ### Leave two empty lines at end of script, not sure of required by Python like other shell scripts or not, don't quote me on that edit: just noticed you said windows, so above for linux, not going to work, but even still wouldn't you need cygwin or something like that and still have to define the python path, or does that not apply under windows? Edited June 8, 2013 by digip Quote Link to comment Share on other sites More sharing options...
proskater123 Posted June 8, 2013 Author Share Posted June 8, 2013 You can run python on windows you just have to define the paths or run it under the python directory using the python.exe Quote Link to comment Share on other sites More sharing options...
proskater123 Posted June 8, 2013 Author Share Posted June 8, 2013 So this is what I have came up with so far. #!/usr/bin/env pythonimport pyDesimport os, sys# Encryption key is a slightly variation of "NtgrBak"KEY = [0x56-8, 0x74, 0x67, 0x72, 0x42, 0x61, 0x6b, 0x00]def derive_des_key(ascii_key): def extract_by_offset(offset): byte_index = offset >> 3 bit_index = byte_index << 3 v0 = (ascii_key[byte_index] << 8) | ascii_key[byte_index+1] v1 = 8 - (offset - bit_index) v0 >>= v11 return v0 & 0xfe k = "" for i in range(0, 7*8, 7): k += chr(extract_by_offset(i)) return kdef decrypt_block(block, key_bytes): k = derive_des_key(key_bytes) des = pyDes.des(k, pyDes.ECB) r = des.decrypt(block) return rdef main(): data = sys.stdin.read() assert (len(data) % 8) == 0 current_key = KEY[:] r = "" for i in range(0, len(data), 8): current_key[0] += 8 if current_key[0] > 0xff: current_key[0] = current_key[0] - 0x100 current_key[1] += 1 block = data[i:i+8] d = decrypt_block(block, current_key) r += d sys.stdout.write® Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.