Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions internal/tests/integration/javascript_mssql_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//go:build integration
// +build integration

package integration_test

import (
"encoding/binary"
"io"
"net"
"time"
)

type javascriptMSSQLFingerprint struct{}

func (j *javascriptMSSQLFingerprint) Execute(filePath string) error {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return err
}
defer func() { _ = ln.Close() }()

go func() {
for {
conn, err := ln.Accept()
if err != nil {
return
}
go handleMSSQLPreloginConn(conn)
}
}()

results, err := runSignedNucleiTemplateAndGetResults(filePath, ln.Addr().String(), debug)
if err != nil {
return err
}
return expectResultsCount(results, 1)
}

func handleMSSQLPreloginConn(conn net.Conn) {
defer func() { _ = conn.Close() }()
_ = conn.SetDeadline(time.Now().Add(5 * time.Second))
buf := make([]byte, 256)
if _, err := io.ReadAtLeast(conn, buf, 8); err != nil {
return
}
_, _ = conn.Write(sampleMSSQLPreloginResponse())
}

func sampleMSSQLPreloginResponse() []byte {
body := []byte{
0x00, 0x00, 0x1f, 0x00, 0x06,
0x01, 0x00, 0x25, 0x00, 0x01,
0x02, 0x00, 0x26, 0x00, 0x01,
0x03, 0x00, 0x27, 0x00, 0x00,
0x04, 0x00, 0x27, 0x00, 0x01,
0x05, 0x00, 0x28, 0x00, 0x00,
0xff,
0x0f, 0x00, 0x07, 0xd0, 0x00, 0x00,
0x02,
0x00,
0x01,
}
header := []byte{0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}
binary.BigEndian.PutUint16(header[2:4], uint16(8+len(body)))
return append(header, body...)
}
1 change: 1 addition & 0 deletions internal/tests/integration/javascript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var jsTestcases = []integrationCase{
{Path: "protocols/javascript/vnc-pass-brute.yaml", TestCase: &javascriptVncPassBrute{}, DisableOn: javascriptDockerDisabled, Serial: true},
{Path: "protocols/javascript/postgres-pass-brute.yaml", TestCase: &javascriptPostgresPassBrute{}, DisableOn: javascriptDockerDisabled, Serial: true},
{Path: "protocols/javascript/mysql-connect.yaml", TestCase: &javascriptMySQLConnect{}, DisableOn: javascriptDockerDisabled, Serial: true},
{Path: "protocols/javascript/mssql-fingerprint.yaml", TestCase: &javascriptMSSQLFingerprint{}},
{Path: "protocols/javascript/multi-ports.yaml", TestCase: &javascriptMultiPortsSSH{}},
{Path: "protocols/javascript/no-port-args.yaml", TestCase: &javascriptNoPortArgs{}},
{Path: "protocols/javascript/telnet-auth-test.yaml", TestCase: &javascriptTelnetAuthTest{}, DisableOn: javascriptDockerDisabled, Serial: true},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
id: mssql-fingerprint

info:
name: MSSQL Fingerprint Test
author: pdteam
severity: info

javascript:
- pre-condition: |
isPortOpen(Host, Port)
code: |
const mssql = require('nuclei/mssql');
const client = new mssql.MSSQLClient();
const isMssql = client.IsMssql(Host, Port);
const info = client.FingerprintMssql(Host, Port);
const ok = isMssql && info && info.Version && info.Version.length > 0 && info.MajorVersion > 0 && info.EncryptionMode && info.EncryptionMode.length > 0 && info.Protocol === "mssql";
Export({
ok: ok,
isMssql: isMssql,
version: info.Version,
majorVersion: info.MajorVersion,
minorVersion: info.MinorVersion,
buildNumber: info.BuildNumber,
encryptionMode: info.EncryptionMode,
protocol: info.Protocol,
transport: info.Transport,
});
args:
Host: "{{Host}}"
Port: "1433"

matchers:
- type: dsl
dsl:
- "success == true"
- "ok == true"
- "isMssql == true"
- "len(version) > 0"
- "majorVersion > 0"
- 'protocol == "mssql"'
- 'transport == "tcp"'
- "len(encryptionMode) > 0"
1 change: 1 addition & 0 deletions pkg/js/generated/go/libmssql/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func init() {

// Objects / Classes
"MSSQLClient": gojs.GetClassConstructor[lib_mssql.MSSQLClient](&lib_mssql.MSSQLClient{}),
"MSSQLInfo": gojs.GetClassConstructor[lib_mssql.MSSQLInfo](&lib_mssql.MSSQLInfo{}),
},
).Register()
}
Expand Down
37 changes: 35 additions & 2 deletions pkg/js/generated/ts/mssql.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


/**
* Client is a client for MS SQL database.
* Internally client uses microsoft/go-mssqldb driver.
Expand Down Expand Up @@ -63,6 +61,20 @@ export class MSSQLClient {
}


/**
* FingerprintMssql gathers MSSQL pre-login fingerprint data from the target.
* @example
* ```javascript
* const mssql = require('nuclei/mssql');
* const info = mssql.FingerprintMssql('acme.com', 1433);
* log(to_json(info));
* ```
*/
public FingerprintMssql(host: string, port: number): MSSQLInfo | null {
return null;
}


/**
* ExecuteQuery connects to MS SQL database using given credentials and executes a query.
* It returns the results of the query or an error if something goes wrong.
Expand Down Expand Up @@ -93,3 +105,24 @@ export interface SQLResult {
Columns?: string[],
}


/**
* MSSQLInfo contains TDS pre-login fingerprint data.
*/
export interface MSSQLInfo {
host?: string,
ip?: string,
port?: number,
protocol?: string,
tls?: boolean,
transport?: string,
version?: string,
majorVersion?: number,
minorVersion?: number,
buildNumber?: number,
encryption?: number,
encryptionMode?: string,
mars?: boolean,
instanceMatches?: boolean,
raw?: string,
}
Loading
Loading