diff --git a/parsers/json2html.ps1 b/parsers/json2html.ps1 new file mode 100644 index 0000000..b22e07d --- /dev/null +++ b/parsers/json2html.ps1 @@ -0,0 +1,398 @@ +# Based on https://github.com/carlospolop/PEASS-ng/blob/master/parsers/json2html.py +# TODO: create the script +function parse_dict { + param ( + [System.Object] $json_dict + ) + + # Parse the given dict from the given json adding it to the HTML file + $dict_text = "" + foreach($obj in $json_dict.psobject.properties){ + $key = $obj.Name + $value = $obj.Value + $n = Get-Random -Minimum 1 -Maximum 999999 + $infos = [System.Collections.ArrayList]@() + + foreach($info in $value."infos"){ + if(([string]$info).StartsWith('http')){ + $infos.Add("$info
`n") + } + else{ + $infos.Add([string]$info + "
`n") + } + } + + $dict_text += "`t`t
`n" + $dict_text += "" + ($infos -join "") + "" + $dict_text += "
`n" + + if($value."lines"){ + $dict_text += $("`n" + (parse_list $value."lines") + "`n") + } + + if($value."sections"){ + $dict_text += (parse_dict $value."sections") + } + } + + return $dict_text + +} + +function parse_list { + param ( + [System.Object] $json_list + ) + # Parse the given list from the given json adding it to the HTML file + + $color_text="" + $color_class="" + + $special_char = [String][char]0x2550 + $special_char_2 = [String][char]0x2563 + + foreach($i in $json_list){ + if(-not $i."clean_text".Contains($special_char*3)){ + if($i."clean_text"){ + $color_text += "
" + $replacement + "") + if($text.Contains($special_char_2)){ + $text = $text.Replace($special_char_2, "
  • ") + $text += "
  • " + } + } + $color_text += "" + $color_class + " " + } + $color_text += "no_color`" >" + $text + "
    `n" + } + + } + } + return $color_text + "`t`t`t
    `n" +} + +function parse_json { + param ( + $json_data + ) + + $body = "" + $i = 1 + + foreach($obj in $json_data.psobject.properties){ + $key = $obj.Name + $value = $obj.Value + $body += " `t`t
    `n
    `n" + $i += 1 + foreach($obj_2 in $value.psobject.properties) { + $key1 = $obj_2.Name + $value1 = $obj_2.Value + if($value1.GetType().BaseType -eq [System.Object]){ + $body += parse_dict $value1 + } + + } + + $body += "`t`t`t
    `n" + } + + return $body +} + +$HTML_HEADER = @" + + + + + + + + + +"@ + +$HTML_END = @" + + + +"@ + +$HTML_INIT_BODY = @" + +
    +
    + +
    + + + +
    +"@ + +$body = @" + +
    +
    + +
    + + + +
    +"@ + +function main { + $json_data = Get-Content $JSON_PATH -Raw | ConvertFrom-Json + $html = $HTML_HEADER + $html += $HTML_INIT_BODY + $html += parse_json $json_data + $html += $HTML_END + + $html | Out-File $HTML_PATH +} + +try { + $JSON_PATH = $(Read-Host "JSON Path") + $HTML_PATH = $(Read-Host "HTML Path") +} +catch { + Write-Host "Error: Please pass the peas.out file and the path to save the html`npeas2html.ps1 " + exit +} + +main \ No newline at end of file