metasploit-framework icon indicating copy to clipboard operation
metasploit-framework copied to clipboard

HighlightJS Hilight rules wanted

Open todb-r7 opened this issue 7 years ago • 3 comments

There's a light desire for custom MSF output format to be parsed and interpreted automatically, so people who use higlightjs can just splat text up and make it look right.

That link there is the HOWTO.

todb-r7 avatar Aug 14 '17 16:08 todb-r7

Note that HilightJS wants a new maintainer, so if you're an open source kinda frood, you can try your hand at a non-security project. :)

In the meantime, I've added the Delayed tag to this.

todb-r7 avatar Jan 17 '18 18:01 todb-r7

HilightJS has a new maintainer, and apparently I've been suckered onto the team to specifically maintain metasploit.js. So, yes, this is still on me, and I'll implement it Real Soon Now. Pinky swear.

todb-r7 avatar Feb 13 '20 18:02 todb-r7

I think I've accidentally done this with our new docs site over here with Github's rouge formatter: https://github.com/rapid7/metasploit-framework/pull/17565

Hoping to get the hljs support added to the blog as well; Although it's most likely not going to be upstreamed as it requires custom scopes to differentiate the print_good/print_warning/print_etc - initial POC here:

hljs.registerLanguage('msf', function () {
    return {
        name: 'msf',
        keywords: {},
        contains: [
            { scope: 'prompt.name', begin: '^(msf\\d?|meterpreter)', relevance: 10 },
            {
                begin: ' (exploit|payload|auxiliary|encoder|evasion|post|nop)\\(',
                end: '>',
                scope: 'test',
                contains: [
                    { scope: 'prompt.mod', begin: '(?!\\()([\\w/]+)(?=\\))' },
                ]
            },
            { scope: 'error', begin: '^\\[\\-\\]' },
            { scope: 'good', begin: '^\\[\\+\\]' },
            { scope: 'status', begin: '^\\[\\*\\]' },
            { scope: 'warning', begin: '^\\[\\!\\]' },
            hljs.QUOTE_STRING_MODE
        ],
        illegal: '\\S'
    };
});

Example

image
Full POC
Before
<pre><code>
msf6 > use auxiliary/scanner/winrm/winrm_login
msf6 auxiliary(scanner/winrm/winrm_login) > run rhost=192.168.123.13 username=Administrator password=p4$$w0rd winrm::auth=kerberos domaincontrollerrhost=192.168.123.13 winrm::rhostname=dc3.demo.local domain=demo.local

[+] 192.168.123.13:88 - Received a valid TGT-Response
[*] 192.168.123.13:5985   - TGT MIT Credential Cache ticket saved to /Users/user/.msf4/loot/20230118120604_default_192.168.123.13_mit.kerberos.cca_451736.bin
[+] 192.168.123.13:88 - Received a valid TGS-Response
[*] 192.168.123.13:5985   - TGS MIT Credential Cache ticket saved to /Users/user/.msf4/loot/20230118120604_default_192.168.123.13_mit.kerberos.cca_889546.bin
[+] 192.168.123.13:88 - Received a valid delegation TGS-Response
[+] 192.168.123.13:88 - Received AP-REQ. Extracting session key...
[+] 192.168.123.13:5985 - Login Successful: demo.local\Administrator:p4$$w0rd
[*] Command shell session 1 opened (192.168.123.1:50722 -> 192.168.123.13:5985) at 2023-01-18 12:06:05 +0000
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf6 auxiliary(scanner/winrm/winrm_login) > sessions -i -1
[*] Starting interaction with 1...

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\Administrator>
</code></pre>

After
<pre><code class="language-msf">
msf6 > use auxiliary/scanner/winrm/winrm_login
msf6 auxiliary(scanner/winrm/winrm_login) > run rhost=192.168.123.13 username=Administrator password=p4$$w0rd winrm::auth=kerberos domaincontrollerrhost=192.168.123.13 winrm::rhostname=dc3.demo.local domain=demo.local

[+] 192.168.123.13:88 - Received a valid TGT-Response
[*] 192.168.123.13:5985   - TGT MIT Credential Cache ticket saved to /Users/user/.msf4/loot/20230118120604_default_192.168.123.13_mit.kerberos.cca_451736.bin
[+] 192.168.123.13:88 - Received a valid TGS-Response
[*] 192.168.123.13:5985   - TGS MIT Credential Cache ticket saved to /Users/user/.msf4/loot/20230118120604_default_192.168.123.13_mit.kerberos.cca_889546.bin
[+] 192.168.123.13:88 - Received a valid delegation TGS-Response
[+] 192.168.123.13:88 - Received AP-REQ. Extracting session key...
[+] 192.168.123.13:5985 - Login Successful: demo.local\Administrator:p4$$w0rd
[*] Command shell session 1 opened (192.168.123.1:50722 -> 192.168.123.13:5985) at 2023-01-18 12:06:05 +0000
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf6 auxiliary(scanner/winrm/winrm_login) > sessions -i -1
[*] Starting interaction with 1...

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\Administrator>
</code></pre>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/a11y-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js"></script>
<script>
// Highlight Metasploit console snippets
hljs.registerLanguage('msf', function () {
    return {
        name: 'msf',
        keywords: {},
        contains: [
            { scope: 'prompt.name', begin: '^(msf\\d?|meterpreter)', relevance: 10 },
            {
                begin: ' (exploit|payload|auxiliary|encoder|evasion|post|nop)\\(',
                end: '>',
                scope: 'test',
                contains: [
                    { scope: 'prompt.mod', begin: '(?!\\()([\\w/]+)(?=\\))' },
                ]
            },
            { scope: 'error', begin: '^\\[\\-\\]' },
            { scope: 'good', begin: '^\\[\\+\\]' },
            { scope: 'status', begin: '^\\[\\*\\]' },
            { scope: 'warning', begin: '^\\[\\!\\]' },
            hljs.QUOTE_STRING_MODE
        ],
        illegal: '\\S'
    };
});
hljs.highlightAll();
</script>


<style>
.language-msf .hljs-prompt.name_ {
    text-decoration: underline;
}
.language-msf .hljs-prompt.mod_ {
    color: #ff4444;
}
.language-msf .hljs-error {
    color: #ff4444;
}
.language-msf .hljs-good {
    color: #b5d86f;
}
.language-msf .hljs-status {
    color: #558bb3;
}
.language-msf .hljs-warning {
    color: #f5ab35;
}
</style>

adfoster-r7 avatar Jan 30 '23 14:01 adfoster-r7

Closing as per the above message; It would be cool to add to linquist support to Github though.

adfoster-r7 avatar Apr 17 '23 11:04 adfoster-r7