Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Commit

Permalink
removed compat.py as it wasn't being used by any function. Removed th…
Browse files Browse the repository at this point in the history
…e dump function from target_info.py as it isn't necessary and required. Added tests to cover target_info.py methods as well as some more lines in compute_response.py
  • Loading branch information
BOREAN, Jordan authored and BOREAN, Jordan committed Aug 7, 2016
1 parent 1f9094f commit 4bf525b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 11 deletions.
7 changes: 0 additions & 7 deletions ntlm3/compat.py

This file was deleted.

4 changes: 0 additions & 4 deletions ntlm3/target_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ def __getitem__(self, key):
def __delitem__(self, key):
del self.fields[key]

def dump(self):
for i in self.fields.keys():
print("%s: {%r}" % (i, self[i]))

def from_string(self, data):
attribute_type = 0xff
while attribute_type is not TargetInfo.MSV_AV_EOL:
Expand Down
21 changes: 21 additions & 0 deletions test/unit/test_compute_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,26 @@ def test_nt_v2_response(self, timestamp_function):
password, server_challenge, target_info,
3, client_challenge).get_nt_challenge_response()

assert actual_response == expected_response
assert actual_target_info == expected_target_info

# This test is different from the other Microsoft examples, they don't have an example where the AV_TIMESTAMP pair is present, using our own expected results
def test_nt_v2_response_with_timestamp_av_pair(self):
test_target_info = target_info
test_target_info[TargetInfo.MSV_AV_TIMESTAMP] = HexToByte('00 00 00 00 00 00 00 00')
expected_response = HexToByte('fb 4e c5 8d 66 2a 1e bc 3b 55 24 97 1d 77 20 7e'
'01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
'aa aa aa aa aa aa aa aa 00 00 00 00 02 00 0c 00'
'44 00 6f 00 6d 00 61 00 69 00 6e 00 01 00 0c 00'
'53 00 65 00 72 00 76 00 65 00 72 00 07 00 08 00'
'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00')
expected_target_info = test_target_info

(actual_response, actual_target_info) = ComputeResponse(
NegotiateFlags.NTLMSSP_ANOYNMOUS, domain, user_name,
password, server_challenge, test_target_info,
3, client_challenge).get_nt_challenge_response()
print ByteToHex(actual_response)

assert actual_response == expected_response
assert actual_target_info == expected_target_info
40 changes: 40 additions & 0 deletions test/unit/test_target_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import unittest2 as unittest

from ntlm3.target_info import TargetInfo
from ..utils import HexToByte

def get_test_target_info():
target_info = TargetInfo()
target_info[TargetInfo.MSV_AV_NB_DOMAIN_NAME] = HexToByte('44 00 6f 00 6d 00 61 00 69 00 6e 00')
target_info[TargetInfo.MSV_AV_NB_COMPUTER_NAME] = HexToByte('53 00 65 00 72 00 76 00 65 00 72 00')

return target_info

class Test_TargetInfo(unittest.TestCase):
def test_del_item(self):
target_info = get_test_target_info()
# Contains the len and id of MSV_AV_NB_COMPUTER_NAME and the EOL as we have remove MSV_AV_NB_DOMAIN_NAME
expected = HexToByte('01 00 0c 00 53 00 65 00 72 00 76 00 65 00 72 00 00 00 00 00')
target_info.__delitem__(TargetInfo.MSV_AV_NB_DOMAIN_NAME)
actual = target_info.get_data()

assert actual == expected

def test_add_item(self):
target_info = get_test_target_info()
expected = HexToByte('02 00 0c 00 44 00 6f 00 6d 00 61 00 69 00 6e 00 01 00 0c 00 53 00'
'65 00 72 00 76 00 65 00 72 00 03 00 0c 00 53 00 65 00 72 00 76 00'
'65 00 72 00 00 00 00 00')
target_info[TargetInfo.MSV_AV_DNS_COMPUTER_NAME] = HexToByte('53 00 65 00 72 00 76 00 65 00 72 00')
actual = target_info.get_data()

assert actual == expected

def test_get_item(self):
target_info = get_test_target_info()
expected_value = HexToByte('44 00 6f 00 6d 00 61 00 69 00 6e 00')
expected_length = len(expected_value)
(actual_length, actual_value) = target_info[TargetInfo.MSV_AV_NB_DOMAIN_NAME]

assert actual_length == expected_length
assert actual_value == expected_value

0 comments on commit 4bf525b

Please sign in to comment.