-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[0.4] Modify json result refer to #19 and fix telnet
- Loading branch information
Showing
6 changed files
with
50 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,64 @@ | ||
package output | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/zhzyker/dismap/internal/flag" | ||
"github.com/zhzyker/dismap/pkg/logger" | ||
"os" | ||
"time" | ||
) | ||
|
||
func Open(Args map[string]interface{}) *os.File { | ||
o := Args["FlagOutput"].(string) | ||
op, err := os.OpenFile(o, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666) | ||
if logger.DebugError(err) { | ||
logger.Error(fmt.Sprintf("Failed to open file %s", logger.Red(o))) | ||
func Open(Args map[string]interface{}) *os.File { | ||
if len(Args["FlagOutJson"].(string)) != 0 { | ||
return openFile(Args["FlagOutJson"].(string)) | ||
} else { | ||
return openFile(Args["FlagOutput"].(string)) | ||
} | ||
return op | ||
} | ||
|
||
func Write(result map[string]interface{}, output *os.File) { | ||
if result["status"].(string) == "close" { | ||
return | ||
} | ||
JsonOutput(result, "save") | ||
content := fmt.Sprintf("%s, %s, %s, %s, %s, %s", | ||
logger.GetTime(), | ||
result["type"], | ||
result["protocol"], | ||
logger.Clean(result["identify.string"].(string)), | ||
result["uri"], | ||
result["banner.string"]) | ||
var text = []byte(content + "\n") | ||
_, err := output.Write(text) | ||
if logger.DebugError(err) { | ||
logger.Error(fmt.Sprintf("Target %s write failed", logger.Red(result["uri"]))) | ||
if len(flag.OutJson) != 0 { | ||
result["banner.byte"] = hex.EncodeToString(result["banner.byte"].([]byte)) | ||
result["date"] = time.Now().Unix() | ||
byteR, _ := json.Marshal(result) | ||
writeContent(output, string(byteR)) | ||
} else { | ||
content := fmt.Sprintf("%s, %s, %s, %s, %s, %s", | ||
logger.GetTime(), | ||
result["type"], | ||
result["protocol"], | ||
logger.Clean(result["identify.string"].(string)), | ||
result["uri"], | ||
result["banner.string"]) | ||
writeContent(output, content) | ||
} | ||
} | ||
|
||
func Close(file *os.File) { | ||
JsonOutput(nil, "write") | ||
err := file.Close() | ||
if logger.DebugError(err) { | ||
logger.Error(fmt.Sprintf("Close file %s exception", logger.Red(file.Name()))) | ||
} else { | ||
logger.Info("The identification results are saved in " + logger.Yellow(file.Name())) | ||
} | ||
} | ||
|
||
func openFile(name string) *os.File { | ||
osFile, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666) | ||
if logger.DebugError(err) { | ||
logger.Error(fmt.Sprintf("Failed to open file %s", logger.Red(name))) | ||
} | ||
return osFile | ||
} | ||
|
||
func writeContent(file *os.File, content string) { | ||
_, err := file.Write([]byte(content + "\n")) | ||
if logger.DebugError(err) { | ||
logger.Error(fmt.Sprintf("Write failed: %s", logger.Red(content))) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters