Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Marsaud Smb2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Marsaud Smb2
Commits
47d84f80
Commit
47d84f80
authored
Feb 14, 2015
by
Benjamin Chelli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make MessageId, ProcessId, SessionId unique at the connection level
parent
23582d1d
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
76 additions
and
53 deletions
+76
-53
lib/messages/close.js
lib/messages/close.js
+1
-0
lib/messages/create.js
lib/messages/create.js
+1
-0
lib/messages/create_folder.js
lib/messages/create_folder.js
+1
-0
lib/messages/negotiate.js
lib/messages/negotiate.js
+1
-0
lib/messages/open.js
lib/messages/open.js
+1
-0
lib/messages/open_folder.js
lib/messages/open_folder.js
+1
-0
lib/messages/query_directory.js
lib/messages/query_directory.js
+1
-0
lib/messages/read.js
lib/messages/read.js
+1
-0
lib/messages/session_setup_step1.js
lib/messages/session_setup_step1.js
+1
-0
lib/messages/session_setup_step2.js
lib/messages/session_setup_step2.js
+1
-0
lib/messages/set_info.js
lib/messages/set_info.js
+1
-0
lib/messages/tree_connect.js
lib/messages/tree_connect.js
+1
-0
lib/messages/write.js
lib/messages/write.js
+1
-0
lib/smb2.js
lib/smb2.js
+22
-7
lib/tools/smb2-forge.js
lib/tools/smb2-forge.js
+1
-1
lib/tools/smb2-message.js
lib/tools/smb2-message.js
+40
-45
No files found.
lib/messages/close.js
View file @
47d84f80
...
@@ -14,6 +14,7 @@ module.exports = message({
...
@@ -14,6 +14,7 @@ module.exports = message({
'
Command
'
:
'
CLOSE
'
'
Command
'
:
'
CLOSE
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
TreeId
'
:
connection
.
TreeId
,
'
TreeId
'
:
connection
.
TreeId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
FileId
'
:
params
.
FileId
'
FileId
'
:
params
.
FileId
...
...
lib/messages/create.js
View file @
47d84f80
...
@@ -16,6 +16,7 @@ module.exports = message({
...
@@ -16,6 +16,7 @@ module.exports = message({
'
Command
'
:
'
CREATE
'
'
Command
'
:
'
CREATE
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
TreeId
'
:
connection
.
TreeId
,
'
TreeId
'
:
connection
.
TreeId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
Buffer
'
:
buffer
'
Buffer
'
:
buffer
...
...
lib/messages/create_folder.js
View file @
47d84f80
...
@@ -16,6 +16,7 @@ module.exports = message({
...
@@ -16,6 +16,7 @@ module.exports = message({
'
Command
'
:
'
CREATE
'
'
Command
'
:
'
CREATE
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
TreeId
'
:
connection
.
TreeId
,
'
TreeId
'
:
connection
.
TreeId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
Buffer
'
:
buffer
'
Buffer
'
:
buffer
...
...
lib/messages/negotiate.js
View file @
47d84f80
...
@@ -12,6 +12,7 @@ module.exports = message({
...
@@ -12,6 +12,7 @@ module.exports = message({
return
new
SMB2Message
({
return
new
SMB2Message
({
headers
:{
headers
:{
'
Command
'
:
'
NEGOTIATE
'
'
Command
'
:
'
NEGOTIATE
'
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
});
});
...
...
lib/messages/open.js
View file @
47d84f80
...
@@ -16,6 +16,7 @@ module.exports = message({
...
@@ -16,6 +16,7 @@ module.exports = message({
'
Command
'
:
'
CREATE
'
'
Command
'
:
'
CREATE
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
TreeId
'
:
connection
.
TreeId
,
'
TreeId
'
:
connection
.
TreeId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
Buffer
'
:
buffer
'
Buffer
'
:
buffer
...
...
lib/messages/open_folder.js
View file @
47d84f80
...
@@ -16,6 +16,7 @@ module.exports = message({
...
@@ -16,6 +16,7 @@ module.exports = message({
'
Command
'
:
'
CREATE
'
'
Command
'
:
'
CREATE
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
TreeId
'
:
connection
.
TreeId
,
'
TreeId
'
:
connection
.
TreeId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
Buffer
'
:
buffer
'
Buffer
'
:
buffer
...
...
lib/messages/query_directory.js
View file @
47d84f80
...
@@ -14,6 +14,7 @@ module.exports = message({
...
@@ -14,6 +14,7 @@ module.exports = message({
'
Command
'
:
'
QUERY_DIRECTORY
'
'
Command
'
:
'
QUERY_DIRECTORY
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
TreeId
'
:
connection
.
TreeId
,
'
TreeId
'
:
connection
.
TreeId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
FileId
'
:
params
.
FileId
'
FileId
'
:
params
.
FileId
...
...
lib/messages/read.js
View file @
47d84f80
...
@@ -14,6 +14,7 @@ module.exports = message({
...
@@ -14,6 +14,7 @@ module.exports = message({
'
Command
'
:
'
READ
'
'
Command
'
:
'
READ
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
TreeId
'
:
connection
.
TreeId
,
'
TreeId
'
:
connection
.
TreeId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
FileId
'
:
file
.
FileId
'
FileId
'
:
file
.
FileId
...
...
lib/messages/session_setup_step1.js
View file @
47d84f80
...
@@ -13,6 +13,7 @@ module.exports = message({
...
@@ -13,6 +13,7 @@ module.exports = message({
return
new
SMB2Message
({
return
new
SMB2Message
({
headers
:{
headers
:{
'
Command
'
:
'
SESSION_SETUP
'
'
Command
'
:
'
SESSION_SETUP
'
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
Buffer
'
:
ntlm
.
encodeType1
(
'
Buffer
'
:
ntlm
.
encodeType1
(
...
...
lib/messages/session_setup_step2.js
View file @
47d84f80
...
@@ -14,6 +14,7 @@ module.exports = message({
...
@@ -14,6 +14,7 @@ module.exports = message({
headers
:{
headers
:{
'
Command
'
:
'
SESSION_SETUP
'
'
Command
'
:
'
SESSION_SETUP
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
Buffer
'
:
ntlm
.
encodeType3
(
'
Buffer
'
:
ntlm
.
encodeType3
(
...
...
lib/messages/set_info.js
View file @
47d84f80
...
@@ -29,6 +29,7 @@ module.exports = message({
...
@@ -29,6 +29,7 @@ module.exports = message({
'
Command
'
:
'
SET_INFO
'
'
Command
'
:
'
SET_INFO
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
TreeId
'
:
connection
.
TreeId
,
'
TreeId
'
:
connection
.
TreeId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
FileInfoClass
'
:
fileInfoClasses
[
params
.
FileInfoClass
]
'
FileInfoClass
'
:
fileInfoClasses
[
params
.
FileInfoClass
]
...
...
lib/messages/tree_connect.js
View file @
47d84f80
...
@@ -13,6 +13,7 @@ module.exports = message({
...
@@ -13,6 +13,7 @@ module.exports = message({
headers
:{
headers
:{
'
Command
'
:
'
TREE_CONNECT
'
'
Command
'
:
'
TREE_CONNECT
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
Buffer
'
:
new
Buffer
(
connection
.
fullPath
,
'
ucs2
'
)
'
Buffer
'
:
new
Buffer
(
connection
.
fullPath
,
'
ucs2
'
)
...
...
lib/messages/write.js
View file @
47d84f80
...
@@ -14,6 +14,7 @@ module.exports = message({
...
@@ -14,6 +14,7 @@ module.exports = message({
'
Command
'
:
'
WRITE
'
'
Command
'
:
'
WRITE
'
,
'
SessionId
'
:
connection
.
SessionId
,
'
SessionId
'
:
connection
.
SessionId
,
'
TreeId
'
:
connection
.
TreeId
,
'
TreeId
'
:
connection
.
TreeId
,
'
ProcessId
'
:
connection
.
ProcessId
}
}
,
request
:{
,
request
:{
'
FileId
'
:
params
.
FileId
'
FileId
'
:
params
.
FileId
...
...
lib/smb2.js
View file @
47d84f80
...
@@ -36,6 +36,9 @@ var SMB = module.exports = function(opt){
...
@@ -36,6 +36,9 @@ var SMB = module.exports = function(opt){
// set default port
// set default port
this
.
port
=
opt
.
port
||
port
;
this
.
port
=
opt
.
port
||
port
;
// set message id
this
.
messageId
=
0
;
// extract share
// extract share
this
.
share
=
matches
[
2
];
this
.
share
=
matches
[
2
];
...
@@ -54,7 +57,19 @@ var SMB = module.exports = function(opt){
...
@@ -54,7 +57,19 @@ var SMB = module.exports = function(opt){
this
.
password
=
opt
.
password
;
this
.
password
=
opt
.
password
;
// set session id
// set session id
this
.
SessionId
=
0
;
this
.
SessionId
=
Math
.
floor
(
Math
.
random
()
*
256
)
&
0xFF
;
// set the process id
// https://msdn.microsoft.com/en-us/library/ff470100.aspx
this
.
ProcessId
=
new
Buffer
([
Math
.
floor
(
Math
.
random
()
*
256
)
&
0xFF
,
Math
.
floor
(
Math
.
random
()
*
256
)
&
0xFF
,
Math
.
floor
(
Math
.
random
()
*
256
)
&
0xFF
,
Math
.
floor
(
Math
.
random
()
*
256
)
&
0xFE
]);
// activate debug mode
this
.
debug
=
opt
.
debug
;
// init connection (socket)
// init connection (socket)
SMB2Connection
.
init
(
this
);
SMB2Connection
.
init
(
this
);
...
...
lib/tools/smb2-forge.js
View file @
47d84f80
...
@@ -89,7 +89,7 @@ SMB2Forge.response = function(c){
...
@@ -89,7 +89,7 @@ SMB2Forge.response = function(c){
* HELPERS
* HELPERS
*/
*/
function
sendNetBiosMessage
(
connection
,
message
)
{
function
sendNetBiosMessage
(
connection
,
message
)
{
var
smbRequest
=
message
.
getBuffer
();
var
smbRequest
=
message
.
getBuffer
(
connection
);
if
(
connection
.
debug
){
if
(
connection
.
debug
){
console
.
log
(
'
--request
'
);
console
.
log
(
'
--request
'
);
...
...
lib/tools/smb2-message.js
View file @
47d84f80
/*
* STATICS
*/
var
messageId
=
0
;
/*
/*
* CONSTANTS
* CONSTANTS
*/
*/
const
protocolId
=
new
Buffer
([
0xFE
,
'
S
'
.
charCodeAt
(
0
),
'
M
'
.
charCodeAt
(
0
),
'
B
'
.
charCodeAt
(
0
)])
const
protocolId
=
new
Buffer
([
0xFE
,
'
S
'
.
charCodeAt
(
0
),
'
M
'
.
charCodeAt
(
0
),
'
B
'
.
charCodeAt
(
0
)])
,
processId
=
new
Buffer
([
0xFF
,
0xFE
,
0x00
,
0x00
])
,
headerTranslates
=
{
,
headerTranslates
=
{
'
Command
'
:
{
'
Command
'
:
{
'
NEGOTIATE
'
:
0x0000
'
NEGOTIATE
'
:
0x0000
...
@@ -50,7 +41,8 @@ const protocolId = new Buffer([0xFE, 'S'.charCodeAt(0), 'M'.charCodeAt(0), 'B'.c
...
@@ -50,7 +41,8 @@ const protocolId = new Buffer([0xFE, 'S'.charCodeAt(0), 'M'.charCodeAt(0), 'B'.c
,
headerLength
=
64
,
headerLength
=
64
,
headerSync
=
[
,
headerSync
=
function
(
processId
,
sessionId
)
{
return
[
[
'
ProtocolId
'
,
4
,
protocolId
]
[
'
ProtocolId
'
,
4
,
protocolId
]
,
[
'
StructureSize
'
,
2
,
headerLength
]
,
[
'
StructureSize
'
,
2
,
headerLength
]
,
[
'
CreditCharge
'
,
2
,
0
]
,
[
'
CreditCharge
'
,
2
,
0
]
...
@@ -63,11 +55,13 @@ const protocolId = new Buffer([0xFE, 'S'.charCodeAt(0), 'M'.charCodeAt(0), 'B'.c
...
@@ -63,11 +55,13 @@ const protocolId = new Buffer([0xFE, 'S'.charCodeAt(0), 'M'.charCodeAt(0), 'B'.c
,
[
'
MessageIdHigh
'
,
4
,
0
]
,
[
'
MessageIdHigh
'
,
4
,
0
]
,
[
'
ProcessId
'
,
4
,
processId
]
,
[
'
ProcessId
'
,
4
,
processId
]
,
[
'
TreeId
'
,
4
,
0
]
,
[
'
TreeId
'
,
4
,
0
]
,
[
'
SessionId
'
,
8
,
0
]
,
[
'
SessionId
'
,
8
,
sessionId
]
,
[
'
Signature
'
,
16
,
0
]
,
[
'
Signature
'
,
16
,
0
]
]
];
}
,
headerASync
=
[
,
headerASync
=
function
(
processId
,
sessionId
)
{
return
[
[
'
ProtocolId
'
,
4
,
protocolId
]
[
'
ProtocolId
'
,
4
,
protocolId
]
,
[
'
StructureSize
'
,
2
,
headerLength
]
,
[
'
StructureSize
'
,
2
,
headerLength
]
,
[
'
CreditCharge
'
,
2
,
0
]
,
[
'
CreditCharge
'
,
2
,
0
]
...
@@ -79,9 +73,10 @@ const protocolId = new Buffer([0xFE, 'S'.charCodeAt(0), 'M'.charCodeAt(0), 'B'.c
...
@@ -79,9 +73,10 @@ const protocolId = new Buffer([0xFE, 'S'.charCodeAt(0), 'M'.charCodeAt(0), 'B'.c
,
[
'
MessageId
'
,
4
]
,
[
'
MessageId
'
,
4
]
,
[
'
MessageIdHigh
'
,
4
,
0
]
,
[
'
MessageIdHigh
'
,
4
,
0
]
,
[
'
AsyncId
'
,
8
]
,
[
'
AsyncId
'
,
8
]
,
[
'
SessionId
'
,
8
,
0
]
,
[
'
SessionId
'
,
8
,
sessionId
]
,
[
'
Signature
'
,
16
,
0
]
,
[
'
Signature
'
,
16
,
0
]
]
];
}
;
;
...
@@ -134,7 +129,7 @@ proto.getResponse = function(){
...
@@ -134,7 +129,7 @@ proto.getResponse = function(){
proto
.
getBuffer
=
function
(){
proto
.
getBuffer
=
function
(
connection
){
var
buffer
=
new
Buffer
(
0xFFFF
)
var
buffer
=
new
Buffer
(
0xFFFF
)
,
length
=
0
,
length
=
0
;
;
...
@@ -142,7 +137,7 @@ proto.getBuffer = function(){
...
@@ -142,7 +137,7 @@ proto.getBuffer = function(){
// SET MESSAGE ID
// SET MESSAGE ID
if
(
!
this
.
isMessageIdSetted
){
if
(
!
this
.
isMessageIdSetted
){
this
.
isMessageIdSetted
=
true
;
this
.
isMessageIdSetted
=
true
;
this
.
headers
[
'
MessageId
'
]
=
messageId
++
;
this
.
headers
[
'
MessageId
'
]
=
connection
.
messageId
++
;
}
}
// HEADERS
// HEADERS
...
@@ -243,7 +238,7 @@ function unTranslate(key, value){
...
@@ -243,7 +238,7 @@ function unTranslate(key, value){
* PRIVATE FUNCTIONS
* PRIVATE FUNCTIONS
*/
*/
function
readHeaders
(
message
,
buffer
){
function
readHeaders
(
message
,
buffer
){
var
header
=
message
.
isAsync
?
headerASync
:
headerSync
var
header
=
(
message
.
isAsync
?
headerASync
:
headerSync
)(
message
.
ProcessId
,
message
.
SessionId
)
,
offset
=
0
,
offset
=
0
;
;
for
(
var
i
in
header
){
for
(
var
i
in
header
){
...
@@ -265,7 +260,7 @@ function readHeaders(message, buffer){
...
@@ -265,7 +260,7 @@ function readHeaders(message, buffer){
function
writeHeaders
(
message
,
buffer
){
function
writeHeaders
(
message
,
buffer
){
var
header
=
message
.
isAsync
?
headerASync
:
headerSync
var
header
=
(
message
.
isAsync
?
headerASync
:
headerSync
)(
message
.
ProcessId
,
message
.
SessionId
)
,
offset
=
0
,
offset
=
0
;
;
for
(
var
i
in
header
){
for
(
var
i
in
header
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment