Ullaakut / nmap

Idiomatic nmap library for go developers
MIT License
922 stars 102 forks source link

Support for XML output (-oX) #92

Closed dac42 closed 1 year ago

dac42 commented 3 years ago

Nice project! One nice-to-have would be support of the -oX parameter. I see the option to output in greppable format (-oG) but not XML.

Ullaakut commented 3 years ago

Hi @dac42 ! That is because this project already uses -oX at all times in order to be able to parse the output of the nmap scan. Currently it always redirects the output of the XML to stdout and reads it directly.

What is the use case you have exactly? I assume then that you want to be able to control where the XML output goes so that you can write it on the filesystem or redirect it as you wish, right?

It could be done but IMO it should be implemented in the library and the library should be able to take an io.Writer on which to write the XML output after it has been parsed. This way, you could do whatever you want with it :) WDYT?

dac42 commented 3 years ago

Hi @Ullaakut, thank you for the very prompt reply! The use case is that I have another tool that is capable of ingesting nmap XML to perform more in depth scanning against services found on the targets. So, if an nmap XML file could be generated, I could sort of chain the tools together.

I'm not picky about implementation details. I just appreciate the responsiveness! :)

Ullaakut commented 3 years ago

Alright, well I can't work on it right now unfortunately, but hopefully a contributor could take a look. I'm not sure when I'll be able to work on it, but in case anyone is interested, I expect it to be around 10-20 mns of work to implement this, here are the steps:

dac42 commented 2 years ago

Hi @Ullaakut, I've been taking a crack at this but seem to have reached the limit of my abilities. The following works for Run and RunWithProgress but I'm not sure how to approach the 2 asynchronous run modes to achieve something similar.

// WithWriter overrides scanner.writer with the writer passed in
func WithWriter(writer io.Writer) Option {
    return func(s *Scanner) {
        s.writer = writer
    }
}

And then the following inside Run and RunWithProgress:

// Connect stdout and additional writer, optionally
if s.writer != nil {
    cmd.Stdout = io.MultiWriter(s.writer, &stdout)
} else {
    cmd.Stdout = &stdout
}

Any thoughts or suggestions?

Ullaakut commented 2 years ago

Hi @dac42, thanks for your attempt :) I'll take a look at this tomorrow when I have some time! I forgot that the async mode had a different way of dealing with the writer, but that seems more tricky than I initially planned indeed 🤔

elivlo commented 1 year ago

Closing this issue because it should be resolved in version v3.0.0. Please reopen it if needed!