CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/meterpreter/extensions/stdapi/net/netstat.rb
Views: 11797
1
# -*- coding: binary -*-
2
3
require 'ipaddr'
4
5
module Rex
6
module Post
7
module Meterpreter
8
module Extensions
9
module Stdapi
10
module Net
11
12
###
13
#
14
# This class represents a connection (listening, connected)
15
# on the remote machine.
16
#
17
###
18
class Netstat
19
20
##
21
#
22
# Constructor
23
#
24
##
25
26
#
27
# Returns a netstat entry and initializes it to the supplied
28
# parameters.
29
#
30
def initialize(opts={})
31
self.local_addr = IPAddr.new_ntoh(opts[:local_addr]).to_s
32
self.remote_addr = IPAddr.new_ntoh(opts[:remote_addr]).to_s
33
self.local_port = opts[:local_port]
34
self.remote_port = opts[:remote_port]
35
self.protocol = opts[:protocol]
36
self.state = opts[:state]
37
self.uid = opts[:uid] || 0
38
self.inode = opts[:inode] || 0
39
self.pid_name = opts[:pid_name]
40
41
self.local_addr_str = sprintf("%s:%d",self.local_addr, self.local_port)
42
if self.remote_port == 0
43
port = "*"
44
else
45
port = self.remote_port.to_s
46
end
47
self.remote_addr_str = sprintf("%s:%s",self.remote_addr, port)
48
end
49
50
51
#
52
# The local address of the connection
53
#
54
attr_accessor :local_addr
55
#
56
# The remote address (peer) of the connection
57
#
58
attr_accessor :remote_addr
59
#
60
# The local port of the connection.
61
#
62
attr_accessor :local_port
63
#
64
# The remote port of the connection.
65
#
66
attr_accessor :remote_port
67
#
68
# The protocol type (tcp/tcp6/udp/udp6)
69
#
70
attr_accessor :protocol
71
#
72
# The state of the connection (close, listening, syn_sent...)
73
#
74
attr_accessor :state
75
#
76
# The uid of the user who started the process to which the connection belongs to
77
#
78
attr_accessor :uid
79
#
80
# The socket inode
81
#
82
attr_accessor :inode
83
#
84
# The name of the process to which the connection belongs to
85
#
86
attr_accessor :pid_name
87
#
88
# The local address of the connection plus the port
89
#
90
attr_accessor :local_addr_str
91
#
92
# The remote address (peer) of the connection plus the port or *
93
#
94
attr_accessor :remote_addr_str
95
end
96
97
end; end; end; end; end; end
98
99