Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jarm: update jarm to not fail on handshake failure #328

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 6 additions & 19 deletions modules/jarm/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
_ "fmt"
jarm "github.com/RumbleDiscovery/jarm-go"
"github.com/zmap/zgrab2"
"io"
"log"
"net"
"strings"
Expand Down Expand Up @@ -103,13 +102,8 @@ func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, inter
// Stores raw hashes returned from parsing each protocols Hello message
rawhashes := []string{}

// Stores final module results
r := Results{}

// Loop through each Probe type
for _, probe := range jarm.GetProbes(target.Host(), int(scanner.GetPort())) {
data := jarm.BuildProbe(probe)

var (
conn net.Conn
err error
Expand All @@ -120,20 +114,14 @@ func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, inter
return zgrab2.TryGetScanStatus(err), nil, err
}

_, err = conn.Write([]byte(data))
_, err = conn.Write(jarm.BuildProbe(probe))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data was already a byte slice and was also only used in this function call.

if err != nil {
rawhashes = append(rawhashes, "")
conn.Close()
continue
}

// ret, err = zgrab2.ReadAvailable(conn)
ret, err = zgrab2.ReadAvailableWithOptions(conn, 1484, 500*time.Millisecond, 0, 1484)
if err != io.EOF && err != nil {
rawhashes = append(rawhashes, "")
conn.Close()
continue
}
ret, _ = zgrab2.ReadAvailableWithOptions(conn, 1484, 500*time.Millisecond, 0, 1484)
Comment on lines 123 to +124
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears to be the case that error responses from the target should still be processed by ParseServerHello which contains logic for handling the various failure responses appropriately.


ans, err := jarm.ParseServerHello(ret, probe)
if err != nil {
Expand All @@ -142,12 +130,11 @@ func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, inter
continue
}

rawhashes = append(rawhashes, string(ans))
rawhashes = append(rawhashes, ans)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ans is already a string. no need to cast.

conn.Close()

}

fprint := jarm.RawHashToFuzzyHash(strings.Join(rawhashes, ","))
r.Fingerprint = string(fprint)
return zgrab2.SCAN_SUCCESS, &r, nil
return zgrab2.SCAN_SUCCESS, &Results{
Fingerprint: jarm.RawHashToFuzzyHash(strings.Join(rawhashes, ",")),
}, nil
}
4 changes: 1 addition & 3 deletions utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ func ReadAvailableWithOptions(conn net.Conn, bufferSize int, readTimeout time.Du
}
return ret, err
}
if err != nil {
return ret, err
}

Comment on lines 147 to +148
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this block err is ALWAYS nil so i removed it.

if n >= maxReadSize {
return ret, err
}
Expand Down