What kind of processes do you find yourself automating in your daily role using python?

Posted Mar 10, 2018, 9:56 PM UTC

4414
PalwaJoko•

Log Files. You can write a python script that runs off of a cron job to do something with Log Files. Copy and put them somewhere. Grep them for specific stuff/filter. etc.

Some people have also used it to extract metadata from files I think. If you're doing an analysis.

That's the most I've seen it. Sadly I never really hard a job that was heavy on python scripting, outside of log files and offense. So I'm quite curious the defensive application of python automation too. There's a few areas I can see it being used if you don't have the tools, such as network sniffing. But I have a lot of tools right now in my current position so I end up not using it a lot.l

8
hondan•

Actually Python can do a lot. Aside from automating web pen tests, Requests module is great at interacting with APIs, OS, subprocess, and sys modules are great with interacting with file systems. You can carve data with PIL and I think scapy even has a module for Python that will allow you to craft and dissect packets. Ord is another good one that allow you to translate between binary, hex, and ASCII. As you said, lists and dictionaries are great for file analysis as well so you can use them to establish baselines and monitor for anomalies.

1
Daddu_tum•

We just automated malware incident response. Python script reads the alerts from Network ips, checks for the host system/user details from DHCP and AD, and creates a ticket in ticketing tool and assigns it to the operations team. Previously, this incident response took around 6hours average before the operations team can get the ticket to work upon.

We have also automated URL reputation check and phishing email checks, reducing manual work of our team.

4
detroitguy16•

Mind expanding on the second part?

2
Daddu_tum•
  1. Created a portal where u can paste the URL (or mail it to a perticular address), and it will give u URL categories and reputation from various sites, including virustotal, McAfee siteadvisor, bluecoat and others. So you don't have to do that manually. And it's in a nicely formated csv report.

  2. Forward the suspected phishing mail to script's mail address. It extracts the urls, attachments and submits to virustotal and other sites, gathers results. Also, it does header analysis, source IP/domain reputation check etc. Also retains results for each URL/IP for 24hours, so no double checks. Than it sends these results back nicely formatted.

I am not a coder, so the code in these script is pathetic, but it gets the job done.

1
PalwaJoko•

What do you say about py scripts already existing that offer these type of things? I haven't looked at every script and I"m sure some need some tweaking for an environment, but a thing I find is when I need python to do something...somebody has already written a script for it.

1
Daddu_tum•

Yes, for URL rep script, I copy pasted from some already available scripts. The goal was, I had to integrate the API of virustotal etc and the result needed to be in a good readable csv format.

For email phishing, I had to create some code from scratch since it had to be able to fetch mails from my mail gateway quarantine. Than do the API submit and pull from various websites, where I got help from already available code online. Integrating email send/receive and fetching URL/attachments was also available online.

I try to find snippets of code, if I can't find one, than only I press my keyboard.

2

Doesn’t your AV/Firewall have automated reports to do this for you?

2
Daddu_tum•

I did this just for the NIPS alerts. Rest of alerts from fw and hips still follows the old siem path.

Security devices send alert logs to siem, from there an email was sent to service desk, which created a ticket and than assigned to infosec operations team. Operations team than works on the ticket by manually checking the NAC/ AD logs and other logs to find/verify infected/attacker system, location and other details. Than the ticket was assigned to the particular location local support guy for AV scan or reimage. For some unknown reasons, siem is not very good in normalizing the logs and was not able to get system name/user ID for 50% alerts. We basically use this script to reduce average IR response/resolution time.

1

Interesting. What siem are you using? Also I’m curious on the organization size that you can have all the workstations pumping into your siem. Where I work, it’s not really feasible for us to feed workstation logs into it, only servers and some special instance workstations. We mainly rely on the AV from being able to provide the machine names, usernames, infection type, file path, etc.

1
Daddu_tum•

Arcsight. Workstation logs are not fed into siem directly. Siem gets logs from firewall, nips, hips+av and some other sources. My org have around 30k+ end user systems, and have offices around the globe. When AV detects a malware, it's all good and easy, but sometimes AV misses the infection for various reasons, and Network ips or firewall tells us about a malware call back.

Then we have to manually track down that system and get it scanned. That's where we needed automation so my team don't have to do manual. Now the team can focus on more important tasks. This step have already saved money because we were able to identify ransomware infected hosts quickly.

1
LiveOverflow•

I use python requests a lot when automating some kind of web attacks. Sometimes it's just a small enumeration PoC or something more advanced like a padding oracle attacks.

3
serverguy5050OP•

So you’re essentially launching attacks/exploits using python?

3
trendy_ass_poser•

Kinda.... Basically

1