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

bug fixes in js , network protocol and flow #4313

Merged
merged 17 commits into from
Nov 2, 2023
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
12 changes: 6 additions & 6 deletions pkg/js/generated/js/libnet/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class NetConn {

/**
* @method
* @description Recv receives data from the connection with a timeout. If N is 0, it will read up to 4096 bytes.
* @param {number} N - The number of bytes to receive.
* @description Recv receives data from the connection with a timeout. If N is 0, it will read all available data.
* @param {number} [N=0] - The number of bytes to receive.
* @returns {Uint8Array} - The received data in an array.
* @throws {error} - The error encountered during data receiving.
* @example
Expand All @@ -35,8 +35,8 @@ class NetConn {

/**
* @method
* @description RecvHex receives data from the connection with a timeout in hex format. If N is 0, it will read up to 4096 bytes.
* @param {number} N - The number of bytes to receive.
* @description RecvHex receives data from the connection with a timeout in hex format. If N is 0, it will read all available data.
* @param {number} [N=0] - The number of bytes to receive.
* @returns {string} - The received data in hex format.
* @throws {error} - The error encountered during data receiving.
* @example
Expand All @@ -50,8 +50,8 @@ class NetConn {

/**
* @method
* @description RecvString receives data from the connection with a timeout. Output is returned as a string. If N is 0, it will read up to 4096 bytes.
* @param {number} N - The number of bytes to receive.
* @description RecvString receives data from the connection with a timeout. Output is returned as a string. If N is 0, it will read all available data.
* @param {number} [N=0] - The number of bytes to receive.
* @returns {string} - The received data as a string.
* @throws {error} - The error encountered during data receiving.
* @example
Expand Down
40 changes: 22 additions & 18 deletions pkg/js/libs/net/net.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net

import (
"bytes"
"context"
"crypto/tls"
"encoding/hex"
Expand All @@ -10,6 +11,7 @@
"syscall"
"time"

"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v3/pkg/types"
)
Expand All @@ -27,7 +29,7 @@
// Open opens a new connection to the address with a timeout.
// supported protocols: tcp, udp
func OpenTLS(protocol, address string) (*NetConn, error) {
config := &tls.Config{InsecureSkipVerify: true}
config := &tls.Config{InsecureSkipVerify: true, MinVersion: tls.VersionTLS10}
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
host, _, _ := net.SplitHostPort(address)
if host != "" {
c := config.Clone()
Expand Down Expand Up @@ -113,30 +115,32 @@
}

// Recv receives data from the connection with a timeout.
// If N is 0, it will read up to 4096 bytes.
// If N is 0, it will read all data sent by the server.
func (c *NetConn) Recv(N int) ([]byte, error) {
c.setDeadLine()
var response []byte
if N > 0 {
response = make([]byte, N)
} else {
response = make([]byte, 4096)
}
length, err := c.conn.Read(response)
if err != nil {
var netErr net.Error
if (errors.As(err, &netErr) && netErr.Timeout()) ||
errors.Is(err, syscall.ECONNREFUSED) { // timeout error or connection refused
return response, nil
var buff bytes.Buffer
defer func() {
if r := recover(); r != nil {
gologger.Error().Msgf("unbounded read from connection caused a panic: %v", r)
}
}()
if buff.Len() < N || N == 0 {
_, err := buff.ReadFrom(c.conn)
if err != nil {
var netErr net.Error
if (errors.As(err, &netErr) && netErr.Timeout()) ||
errors.Is(err, syscall.ECONNREFUSED) { // timeout error or connection refused
return buff.Bytes(), nil
}
return buff.Bytes(), err
}
return response[:length], err
}
return response[:length], nil
return buff.Bytes(), nil
}

// RecvString receives data from the connection with a timeout
// output is returned as a string.
// If N is 0, it will read up to 4096 bytes.
// If N is 0, it will read all data sent by the server.
func (c *NetConn) RecvString(N int) (string, error) {
bin, err := c.Recv(N)
if err != nil {
Expand All @@ -147,7 +151,7 @@

// RecvHex receives data from the connection with a timeout
// in hex format.
// If N is 0, it will read up to 4096 bytes.
// If N is 0,it will read all data sent by the server.
func (c *NetConn) RecvHex(N int) (string, error) {
bin, err := c.Recv(N)
if err != nil {
Expand Down
Loading