Skip to content

Commit 1559e5f

Browse files
committed
pwn_bdba_scan Driver - work-around for rare race condition in finding product when getting apps by group
1 parent 81da574 commit 1559e5f

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $ cd /opt/pwn
3737
$ ./install.sh
3838
$ ./install.sh ruby-gem
3939
$ pwn
40-
pwn[v0.4.956]:001 >>> PWN.help
40+
pwn[v0.4.957]:001 >>> PWN.help
4141
```
4242

4343
[![Installing the pwn Security Automation Framework](https://raw.githubusercontent.com/0dayInc/pwn/master/documentation/pwn_install.png)](https://youtu.be/G7iLUY4FzsI)
@@ -52,7 +52,7 @@ $ rvm use ruby-3.3.0@pwn
5252
$ gem uninstall --all --executables pwn
5353
$ gem install --verbose pwn
5454
$ pwn
55-
pwn[v0.4.956]:001 >>> PWN.help
55+
pwn[v0.4.957]:001 >>> PWN.help
5656
```
5757

5858
If you're using a multi-user install of RVM do:
@@ -62,7 +62,7 @@ $ rvm use ruby-3.3.0@pwn
6262
$ rvmsudo gem uninstall --all --executables pwn
6363
$ rvmsudo gem install --verbose pwn
6464
$ pwn
65-
pwn[v0.4.956]:001 >>> PWN.help
65+
pwn[v0.4.957]:001 >>> PWN.help
6666
```
6767

6868
PWN periodically upgrades to the latest version of Ruby which is reflected in `/opt/pwn/.ruby-version`. The easiest way to upgrade to the latest version of Ruby from a previous PWN installation is to run the following script:

bin/pwn_bdba_scan

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ begin
111111
group_id: parent_group_id
112112
)
113113

114+
# Break out of infinite loop if status is anything other than 'B' (i.e. 'Busy')
115+
# Possible status other than 'B' is:
116+
# 'R' (i.e. 'Ready') or
117+
# 'F' (i.e. 'Fail')
114118
break if scan_progress_resp[:products].none? { |p| p[:status] == 'B' } || report_only
115119

116120
# Cancel queued scan if it's been queued for more than 90 minutes
@@ -134,9 +138,32 @@ begin
134138
scan_progress_busy_duration += 10
135139
end
136140

137-
find_product = scan_progress_resp[:products].find { |p| p[:name] == CGI.escape(File.basename(target_file)) }
141+
raise 'ERROR: BDBA Scan Failed - Check BDBA Logs for More Info...' if scan_progress_resp[:products].any? { |p| p[:status] == 'F' }
138142

139-
raise NoMethodError if find_product.nil?
143+
# Account for rare race condition scenario where get_apps_by_group may need to be called
144+
# multiple times to find the product
145+
find_product = nil
146+
find_product_attempts = scan_attempts
147+
print 'Looking for Product in Apps by Group...'
148+
loop do
149+
find_product = scan_progress_resp[:products].find { |p| p[:name] == CGI.escape(File.basename(target_file)) }
150+
break unless find_product.nil?
151+
152+
find_product_attempts += 1
153+
154+
raise "ERROR: Cannot Find Product in Apps by Group:\n#{scan_progress_resp}" if find_product_attempts >= scan_attempts
155+
156+
10.times do
157+
print '.'
158+
sleep 1
159+
end
160+
161+
scan_progress_resp = PWN::Plugins::BlackDuckBinaryAnalysis.get_apps_by_group(
162+
token: token,
163+
group_id: parent_group_id
164+
)
165+
end
166+
puts 'complete.'
140167

141168
product_id = find_product[:product_id]
142169

@@ -149,7 +176,6 @@ begin
149176

150177
puts "\nReport Saved to: #{report_path}"
151178
rescue IO::TimeoutError,
152-
NoMethodError,
153179
RestClient::BadGateway,
154180
RestClient::BadRequest,
155181
RestClient::Exceptions::OpenTimeout,

lib/pwn/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module PWN
4-
VERSION = '0.4.956'
4+
VERSION = '0.4.957'
55
end

0 commit comments

Comments
 (0)