This forum is in archive mode. You will not be able to post new content.

Author Topic: python for exploitation and RE?  (Read 728 times)

0 Members and 1 Guest are viewing this topic.

Kiuhnm

  • Guest
python for exploitation and RE?
« on: October 27, 2014, 08:36:18 PM »
When I used to crack software I wrote all my code (loaders, etc...) in C++.
It seems that many now use Python, but is it really a good alternative?
I'd like to write a script which searches for a pattern in the .text section of a given module of a given process.
In C++ I used Win32 API directly. What's the right way in Python?

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: python for exploitation and RE?
« Reply #1 on: October 27, 2014, 08:42:52 PM »
The best PE library for Python is this: https://code.google.com/p/pefile/
I am not sure that it does what you need. It is for static parsing and editing.
« Last Edit: October 27, 2014, 08:44:19 PM by Deque »

Offline TheWormKill

  • EZ's Scripting Whore
  • Global Moderator
  • Knight
  • *
  • Posts: 257
  • Cookies: 66
  • The Grim Reaper of Worms
    • View Profile
Re: python for exploitation and RE?
« Reply #2 on: October 27, 2014, 09:06:32 PM »
I'd say either use something like Capstone (a disassembly library) to get your information from the file (probably using pefile, too) and afterwards write the analysis in Python, or load your file in IDA and use IDAPython to do your analysis. Either way, python is very good for what you want to accomplish.
Stuff I did: How to think like a superuser, Iridium

He should make that "Haskell"
Quote
<m0rph-is-gay> fuck you thewormkill you python coding mother fucker

Kiuhnm

  • Guest
Re: python for exploitation and RE?
« Reply #3 on: October 27, 2014, 09:37:46 PM »
Capstone is certainly something I need, but I'm not so sure about IDA and pefile. I need to examine memory, not files on disk. A file could be packed, encrypted, etc... so it wouldn't be the same thing.

Offline TheWormKill

  • EZ's Scripting Whore
  • Global Moderator
  • Knight
  • *
  • Posts: 257
  • Cookies: 66
  • The Grim Reaper of Worms
    • View Profile
Re: python for exploitation and RE?
« Reply #4 on: October 27, 2014, 09:47:55 PM »
ah. Sorry, seems I've read too fast. What about PyDbg? it's a debugger, so memory access is possible, as well as "intelligent" analysis.

Might I ask, what you're doing? You made me curious.
« Last Edit: October 27, 2014, 09:48:34 PM by TheWormKill »
Stuff I did: How to think like a superuser, Iridium

He should make that "Haskell"
Quote
<m0rph-is-gay> fuck you thewormkill you python coding mother fucker

Kiuhnm

  • Guest
Re: python for exploitation and RE?
« Reply #5 on: October 27, 2014, 11:25:40 PM »
Thanks. Sounds perfect.

edit: PyDbg isn't maintained anymore. I'm going to use WinAppDbg.
« Last Edit: October 28, 2014, 04:34:02 PM by Kiuhnm »

Kiuhnm

  • Guest
Re: python for exploitation and RE?
« Reply #6 on: October 28, 2014, 09:00:10 PM »
Might I ask, what you're doing? You made me curious.

I'm trying to learn exploitation in Windows. There are many little tools available to search for "pop pop ret", "jmp esp", etc..., but I want to write my own tools because writing them is very instructive and it gives me more control.
For instance, why should I search only for "pop pop ret" and not "pop inc pop ret"?
As an example, metasploit has a pattern generator that's limited to 20280 bytes, so I wrote one that supports more than 5 million bytes (https://github.com/mtomassoli/pattern).

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.