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

Update to Python 3, code reformat make it more readable and pythonic. #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

crb912
Copy link

@crb912 crb912 commented Nov 13, 2018

No description provided.

@aph3rson aph3rson self-requested a review March 27, 2019 17:49
@aph3rson
Copy link

@crb912 sorry this has sat for so long, I'll take a look real quick.

Copy link

@aph3rson aph3rson left a comment

Choose a reason for hiding this comment

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

Thanks for the PR - looks like there's some changes to make it even more Pythonic, as well as some grammatical fixes.

"""
unpack all rsa data.
"""
def get_value(x):

Choose a reason for hiding this comment

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

get_value is solely used for L79-L84, could these possibly be squashed to something that returns a tuple of the key values from the file contents?

data = base64.b64encode(raw)

# chop data up into lines of certain width
width = 64
chopped = [data[i:i + width] for i in xrange(0, len(data), width)]
chopped = [data[i:i + width].decode('utf-8') for i in range(0, len(data), width)]

Choose a reason for hiding this comment

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

Is it safe to assume that this content will be UTF-8 encoded? Wouldn't it matter on the OS's preferred encoding on the server?

for magic in magic_headers:
offset = self.file_content.find(magic.encode(encoding='ascii'))
if offset:
print("Success find key type! key type:{}, key start offset:0x"

Choose a reason for hiding this comment

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

Grammatical improvements needed here.

Suggested change
print("Success find key type! key type:{}, key start offset:0x"
print("Successfully found key type {} at offset:0x"

parse_mem.py Outdated Show resolved Hide resolved
parse_mem.py Outdated Show resolved Hide resolved
parse_mem.py Show resolved Hide resolved
return v


t = SshKeyParse()

Choose a reason for hiding this comment

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

L141-L145 should be moved to a main() method with an if __name__ == __main__: or similar.


def read(self, fp):
"""
Reads a file and stories it in self.file_content

Choose a reason for hiding this comment

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

Minor typo.

Suggested change
Reads a file and stories it in self.file_content
Reads a file and stores it in self.file_content

return found_keys
print("Not find any optional keys match any one in:{}".format(
magic_headers))
print("Program exit!")

Choose a reason for hiding this comment

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

This isn't guaranteed to cause the program to exit - see my comments near L141 about this.

Suggested change
print("Program exit!")

for key_type in valid_key:
if "ssh-rsa" == key_type:
self.get_rsa_key(output_fp)
print("\nhave output {} key, File Path:{}".format(

Choose a reason for hiding this comment

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

The \n is at the beginning of the print line, which can mess with shells - also, what's the purpose of this?

@aph3rson aph3rson assigned aph3rson and crb912 and unassigned aph3rson Mar 27, 2019
aph3rson and others added 2 commits March 28, 2019 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants