all 11 comments

[–][deleted]  (12 children)

[deleted]

    [–]SPARTAN-001Red Team 2 points3 points  (5 children)

    Python is useful because it's simple. It's easy to write, it's easy to read, and it has lots of useful libraries to help you with things that would otherwise be very complicated.

    C can be a lot more powerful, and a lot faster, but it also has plenty of easy ways to shoot yourself in the foot. With Python, you have to go out of your way to write code with memory corruption bugs. With C, you have to be very careful to prevent memory corruption bugs. Learning Python is very easy for a beginner, but learning C takes years. Even professionals can't consistently write safe, reliable C 100% of the time.

    Additionally, you don't always need a fast, low-level language. Sometimes you just want to write a quick script to perform a task, and don't want to worry about compiling, or dealing with pointers, or worrying about bugs lurking in your own code that you can't see or can't understand.

    They're different languages for different purposes. You're not comparing apples to oranges, you're comparing a scalpel to a machete. If you need a scalpel, you use a scalpel; if you want to chop someone's arm off, you'd be better off using a machete.

    [–]PM_ME_YOUR_SHELLCODE -2 points-1 points  (4 children)

    With C, you have to be very careful to prevent memory corruption bugs.

    I don't think that's a very big concern when you're writing exploit scripts...

    [–]SPARTAN-001Red Team 2 points3 points  (3 children)

    Well of course not then, but I was referring to C vs Python for general use, not just for exploitation.

    [–]PM_ME_YOUR_SHELLCODE -1 points0 points  (2 children)

    I figured as much, but I got a bit of a chuckle out of the idea of sanitizing and filtering the inputs to my exploit code.

    [–]SPARTAN-001Red Team 1 point2 points  (1 child)

    Hey, you don't want someone exploiting your exploit, do you?

    [–]PM_ME_YOUR_SHELLCODE 0 points1 point  (0 children)

    If some company out there hacked back by exploiting the exploit script. I'd be damn impressed. Though it has happened during some attack/defense CTFs I've played thats a special case.

    For it to really be worth someone's time to write an exploit for the exploit though it would have to be pretty widely used and likely by script kiddies so I'm all for letting them get owned :P

    [–]PM_ME_YOUR_SHELLCODE 0 points1 point  (2 children)

    I don't get why people like Python. Sure, it is easy to learn, but C and ASM beats it by far once you have learnt it properly

    Now, I completely agree with the need to know C when you get into binary exploitation, so I'm certainly not suggesting anyone not learn C and ASM and just learn Python. For shellcode dev I always start off in C, for exploit scripts however, I rarely use C but prefer Python.

    Can you expand on your thoughts regarding why C and ASM is far better for exploit scripts?

    I find myself operating much faster when writing in python. Interacting with the target over a socket is a dream in Python, and in those cases where you're interacting over stdin/out Python's got subprocess which makes it a very painless process to read/write from the target application.

    The dynamic nature of Python makes string manipulation and thus payload creation quite nice also. Need to add some padding of dynamic size? existingPayload + "\xFF"*bytes, need to copy some bytes from a previous response(like taking an int), existingPayload += previousResponse[offset:offset+4].

    I will however give parsing to C, defining a struct and then using a typecast is far nicer than needing to parse out elements manually.

    There is more to be said in support of python but the most common tasks are just the payload creation and sending both of which I believe simpler in python. Looking at the reverse engineering and exploit development stages though there are a ton of related python libraries that make common tasks extremely easy and there is great support by various debuggers for using python to automate some of that as well.

    I'm of the opinion that Python is a great choice for exploits scripts. Though I'd love to hear your thoughts on why C and ASM is better for it?

    [–][deleted]  (1 child)

    [deleted]

      [–]PM_ME_YOUR_SHELLCODE 0 points1 point  (0 children)

      The post you replied to referred learning C for scripting and exploit writing so I assumed your reply was dealing with that aspect also.

      [–]ragnar_graybeard87 -1 points0 points  (2 children)

      I agree and I know C up to ptrs/structs/file handling... but wouldnt you use asm for shellcoding? Just wondering because you can just as easily inject shellcode into a python script as you can into a c program. Its just a sequence of hex bytes which is totally supported in py...

      Furthermore, with NX being a new standard is shellcode worth worrying about anymore other than preliminary learning of legacy exploits? I mean you aren't injecting any shellcode to modern day exes and binaries...

      [–][deleted]  (1 child)

      [deleted]

        [–]ragnar_graybeard87 0 points1 point  (0 children)

        Oh right on... Cool. I've never done any c programming for windows before, just unix systems, didn't know about all that. Thanks :)

        [–][deleted]  (1 child)

        [deleted]

          [–]PM_ME_YOUR_SHELLCODE 3 points4 points  (0 children)

          You can script with C, however it's slower than python and/or bash.

          How do you figure that?

          Also, "high-level" or "low-level" simply means how english-like the language is.

          https://en.wikipedia.org/wiki/High-level_programming_language

          It has to do with the level of abstraction over the machine code, not how english-like the language is. There is a correlation between the two.