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

added challenge response algo #12

Closed
wants to merge 1 commit into from
Closed

added challenge response algo #12

wants to merge 1 commit into from

Conversation

snoremaster3000
Copy link

added --unlock option to do challenge/response on newer LGs

Copy link
Owner

@Lekensteyn Lekensteyn left a comment

Choose a reason for hiding this comment

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

Can you add relevant links to issues/pcaps in the commit message so it is easier to validate the functionality? Thanks for your work!

key2_t_xor = ''
i = 0
while i <= 28:
key2_t_xor += chr(ord(key2_t[i]) ^ ord(kilo_challenge[3]))
Copy link
Owner

Choose a reason for hiding this comment

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

For Python 3 compatibility, consider using b'' as empty byte string and using the struct module. Untested, but should give an idea:

key2_t_xor = b''
challenge_word = struct.unpack("<I", kilo_challenge)[0]
for i in range(0, 28 + 1, 4):
    word = struct.unpack_from("!I", key2_t, i)
    key2_t_xor += struct.pack("!I", word ^ challenge_word)
return key2_t_xor

def do_aes_encrypt(key2_t_xor):
plaintext = b''
for k in range(0,16):
plaintext += chr(k)
Copy link
Owner

Choose a reason for hiding this comment

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

Try int_as_byte instead of chr in order to handle Python 2/3

request_kilo = make_request(b'KILO', args=[b'CENT', b'\0\0\0\0', b'\0\0\0\0', b'\0\0\0\0'])
kilo_header, kilo_response = comm.call(request_kilo)
kilo_challenge = kilo_header[8:12]
chalstring = ":".join("{:02x}".format(ord(k)) for k in kilo_challenge)
Copy link
Owner

Choose a reason for hiding this comment

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

This does not work with Python 3, can you change it to:

..format(k for k in bytearray(kilo_challenge))

similar comment for respstring below

kilo_challenge = kilo_header[8:12]
chalstring = ":".join("{:02x}".format(ord(k)) for k in kilo_challenge)
_logger.debug("Challenge: %s" %chalstring)
key2 = 'qndiakxxuiemdklseqid~a~niq,zjuxl' # if this doesnt work try 'lgowvqnltpvtgogwswqn~n~mtjjjqxro'
Copy link
Owner

Choose a reason for hiding this comment

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

Probably needs key2 = b'qn...' for Python 3 compat

@steadfasterX
Copy link
Contributor

What exactly is the meaning of using --unlock? will it unlock a locked device or what?

steadfasterX added a commit to steadfasterX/lglaf that referenced this pull request Feb 28, 2017
@Lekensteyn
Copy link
Owner

@steadfasterX I think it "unlocks" some commands in the current session which would otherwise be disallowed (and this would probably not persist after a reboot).

@steadfasterX
Copy link
Contributor

steadfasterX commented Feb 28, 2017

True when i do not use the unlock option i cant do anything in the shell! Even ls or pwd failing with an error but when I use the unlock option it works! OK the name is misleading then I think --auth would be better if that's all it does..
I have a lg g4 device.
From my point of view this code needs is absolutely required to be merged. Besides that it need to be done for all other py scripts as well like partitions.py because I cant use them while getting the same error..

EDIT
It differs between the bootloader versions.
For LL I do not need it
For MM i need to use it..

@anarcat
Copy link
Contributor

anarcat commented Aug 4, 2017

using this, i get a little further in rooting this LG G3 D852 phone. Unfortunately, it doesn't actually works:

$ sudo python lglaf.py  --unlock
LGLAF.py by Peter Wu (https://lekensteyn.nl/lglaf)
Type a shell command to execute or "exit" to leave.
# sh /data/local/tmp/lg_root.sh dummy 1 /data/local/tmp/UPDATE-SuperSU-v2.46.zip /data/local/tmp/busybox
Hello, I am LAF. Nice to meet you.

Nice to meet you too... I guess they know we're out here eh?

steadfasterX referenced this pull request in steadfasterX/lglaf Aug 21, 2017
this is based on PR #12 with the following difference:

instead of adding a --unlock option to lglaf.py I use an own executable.
The reason is that within download mode you need to authenticate
only ONCE ( - IF you need to) and afterwards you're able to exec every
other action like partitions.py etc without doing it again (until you reboot
into download mode again ofc).
gmt pushed a commit to gmt/lglaf that referenced this pull request Sep 23, 2017
this is based on PR Lekensteyn#12 with the following difference:

instead of adding a --unlock option to lglaf.py I use an own executable.
The reason is that within download mode you need to authenticate
only ONCE ( - IF you need to) and afterwards you're able to exec every
other action like partitions.py etc without doing it again (until you reboot
into download mode again ofc).
@Lekensteyn
Copy link
Owner

This was merged into #27, thank you for the proposal (you got acknowledged in the commit message)!

@Lekensteyn Lekensteyn closed this Nov 27, 2017
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.

4 participants