0

I'm writing a script which requires me to get NT hashes. I know I can do this using impacket's secretsdump.py but how do I do it from within a python script? I know I can do it using subprocess.call() but I need a way that works if I build an executable of the script (i.e. assuming that the system I'm running it on does not have python installed).

EDIT:
Tried out Carcigenicate's comment and I'm running into another issue now:
import impacket.examples.secretsdump imports impacket/impacket/examples/secretsdump.py while I need to import impacket/examples/secretsdump.py. How do I do this?

magikarp
  • 460
  • 1
  • 8
  • 22
  • 2
    Does `secretsdump.py` not allow for importing? Many modules allow for both command line execution and importing to manually call functions. Read the module, see how it executes when it's run as a command (look for `if __name__ == "__main__"`), then replicate that as you need. – Carcigenicate Jan 02 '21 at 12:40
  • Thank @Carcigenicate! Edited the question for further info. – magikarp Jan 02 '21 at 13:07
  • Then do `import examples.secretsdump` – smci Jan 02 '21 at 13:14
  • @smci, that doesn't work. `examples` isn't a module on its own. Also, when I install `impacket` using pip, it installs whatever is inside [impacket/impacket](https://github.com/SecureAuthCorp/impacket/tree/ac307704949a55c3619a2fb6c8369b974a226592/impacket). Do correct me if I'm wrong. – magikarp Jan 02 '21 at 13:21
  • 1
    @Shreya The second link you posted has, as I mentioned, an `if __name__ == "__main__"` that outlines how the modules is executed. If it doesn't have proper install instructions, download it locally, and attempt to import it. Any errors you get will direct you from there. – Carcigenicate Jan 02 '21 at 13:34
  • 1
    See: [Brenbarn's answer to "Relative imports for the billionth time"](https://stackoverflow.com/a/14132912/202229) – smci Jan 02 '21 at 14:59

0 Answers0