Skip to content

Commit

Permalink
🐛 fix: SOCKS4 reply version fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
MoIzadloo committed Apr 19, 2023
1 parent 87e858c commit 88fcdde
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/obfs/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class Http extends ObfsMethod {
)
const m = regex.exec(message.toString())
if (m) {
if (m[1] !== this.method || m[2] !== this.path || m[3] !== '1.1') {
return false
if (m[1] === this.method || m[2] === this.path || m[3] === '1.1') {
return true
}
}
return true
return false
}

deObfuscate(message: Buffer): Buffer {
Expand Down
2 changes: 1 addition & 1 deletion src/server/handlers/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const createRelay = (
if (info.version === SOCKSVERSIONS.socks5) {
version = SOCKSVERSIONS.socks5
} else {
version = 1
version = 0
}
tcpPortUsed
.check(port)
Expand Down
4 changes: 2 additions & 2 deletions src/server/handlers/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const connect = handler((info, socket, obfs) => {
if (info.version === SOCKSVERSIONS.socks5) {
version = SOCKSVERSIONS.socks5
} else {
version = 1
version = 0
}
const connection = net.connect(info.address.port, info.address.host, () => {
if (connection.remotePort && connection.remoteAddress) {
Expand Down Expand Up @@ -49,6 +49,6 @@ export const connect = handler((info, socket, obfs) => {
)
}
}
socket.write(reply.toBuffer())
socket.write(obfs.obfuscate(reply.toBuffer()))
})
})
5 changes: 2 additions & 3 deletions test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Address from '../src/helper/address'
import * as dns from 'dns'
import net from 'net'
import Readable from '../src/helper/readable'
import obfs from '../src/obfs/obfs'

jest.setTimeout(20000)
const serverPort = 3369
Expand Down Expand Up @@ -267,8 +266,8 @@ describe('client useObfs', () => {
})
})

test('bind', (done) => {
connect(serverPort, serverHost, 4)
test('useObfs HTTP with no cipher bind', (done) => {
connect(serverPort, serverHost, 5)
.useObfs(obfsMethods.http())
.bind(0, '0.0.0.0')
.then((info) => {
Expand Down

0 comments on commit 88fcdde

Please sign in to comment.