![]() SuckerPunch allows me to parse output and log files while the CLI program is running in the background. Here is an example of using SuckerPunch: class Tool def run(async=false) if async (self) else sleep 15 $stdout.write "This is Async" sleep 15 end end end class Async include ::SuckerPunch::Job workers 3 def run(obj) obj.run end end tool = Tool.new n(true) puts "hello" puts "test" sleep 40 SuckerPunch is a pretty simple gem that makes queueing asynchronous tasks very easy. In order to interact with log files and not block up the API, I use a gem called SuckerPunch to handle asynchronous tasking. RProgram is a blocking process and runs as long as the CLI program is processing. prog -o test.txt Queueing Asynchronous Tasks Run it: n do |p| p.outfile = 'test.txt' end Here is a small example of how RProgram works:ĭefine a flag: short_option :flag => '-o', :name => :outfile One thing to note is that arguments are ordered by assignment, so if your program is sensitive to the order of certain flags, make sure you assign the variables in the order you would normally. Mapping an entire program is relatively quick, and RProgram includes additional options for multiple arguments per flag, trailing equal signs, and trailing arguments. It basically allows you to map out any flags as methods to an object. RProgram was built to give developers a simple and powerful way to run command line programs from within ruby. ![]() After looking through the source code, I noticed it was using a library, called RProgram, to wrap the nmap binary. While researching various ways to interface with CLI programs, I stumbled upon a ruby gem called ruby-nmap. We decided to use HashCat for the backend hash-cracking tool, and we needed to come up with a way to communicate with multiple cracking sessions for the service to work.ĭownload HashCat API on GitHub → Interfacing with CLI Programs The goal of the project was to leverage cloud-based GPU systems to crack password hashes while offering users a clean, powerful interface. ![]() The first project I worked on at Praetorian was a tool called Project Mars (formerly PWAudit). Hopefully, these techniques and libraries will be helpful to you when building out new web applications and frameworks. In this post, I’ll share some of the libraries and techniques I have used to build out APIs for CLI programs, such as HashCat and nmap. I came across this problem more than once during the development of a couple of projects here at Praetorian. Have you ever had an amazing idea for automating two or more pieces of technology and then realized one of them doesn’t have an API? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |