├── test ├── VERSION.md ├── preview.png ├── .github └── FUNDING.yml ├── LICENSE.md ├── Utils.php ├── s3-buckets-bruteforcer.php ├── README.md ├── GoogleBucket.php ├── DigitaloceanBucket.php ├── AmazonBucket.php └── BucketBruteForcer.php /test: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /VERSION.md: -------------------------------------------------------------------------------- 1 | 1.2.0 2 | -------------------------------------------------------------------------------- /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gwen001/s3-buckets-finder/HEAD/preview.png -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [gwen001] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2022 Gwendal Le Coguic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Utils.php: -------------------------------------------------------------------------------- 1 | '0', 14 | 'black' => '0;30', 15 | 'red' => '0;31', 16 | 'green' => '0;32', 17 | 'orange' => '0;33', 18 | 'blue' => '0;34', 19 | 'purple' => '0;35', 20 | 'cyan' => '0;36', 21 | 'light_grey' => '0;37', 22 | 'dark_grey' => '1;30', 23 | 'light_red' => '1;31', 24 | 'light_green' => '1;32', 25 | 'yellow' => '1;33', 26 | 'light_blue' => '1;34', 27 | 'light_purple' => '1;35', 28 | 'light_cyan' => '1;36', 29 | 'white' => '1;37', 30 | ); 31 | 32 | 33 | public static function help( $error='' ) 34 | { 35 | if( is_file(__DIR__.'/README.md') ) { 36 | $help = file_get_contents( __DIR__.'/README.md' )."\n"; 37 | preg_match_all( '#```(.*?)```#s', $help, $matches ); 38 | //var_dump($matches); 39 | if( count($matches[1]) ) { 40 | echo trim($matches[1][0])."\n\n"; 41 | } 42 | } else { 43 | echo "No help found!\n"; 44 | } 45 | 46 | if( $error ) { 47 | echo "Error: ".$error."!\n"; 48 | } 49 | 50 | exit(); 51 | } 52 | 53 | 54 | public static function isIp( $str ) { 55 | return filter_var( $str, FILTER_VALIDATE_IP ); 56 | } 57 | 58 | 59 | public static function isEmail( $str ) 60 | { 61 | return filter_var( $str, FILTER_VALIDATE_EMAIL ); 62 | } 63 | 64 | 65 | public static function _print( $str, $color ) 66 | { 67 | echo "\033[".self::T_SHELL_COLORS[$color]."m".$str." \033[0m"; 68 | } 69 | public static function _println( $str, $color ) 70 | { 71 | self::_print( $str, $color ); 72 | echo "\n"; 73 | } 74 | 75 | 76 | 77 | public static function _array_search( $array, $search, $ignore_case=true ) 78 | { 79 | if( $ignore_case ) { 80 | $f = 'stristr'; 81 | } else { 82 | $f = 'strstr'; 83 | } 84 | 85 | if( !is_array($search) ) { 86 | $search = array( $search ); 87 | } 88 | 89 | foreach( $array as $k=>$v ) { 90 | foreach( $search as $str ) { 91 | if( $f($v, $str) ) { 92 | return $k; 93 | } 94 | } 95 | } 96 | 97 | return false; 98 | } 99 | 100 | 101 | public static function format_bytes( $size ) 102 | { 103 | $units = array('b', 'kb', 'mb', 'gb', 'tb'); 104 | for( $i=0 ; $size>=1024 && $i<4 ; $i++ ) { 105 | $size /= 1024; 106 | } 107 | return round($size, 2).$units[$i]; 108 | } 109 | } 110 | 111 | ?> 112 | -------------------------------------------------------------------------------- /s3-buckets-bruteforcer.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | $v ) 42 | { 43 | switch( $k ) 44 | { 45 | case 'bucket': 46 | $bruteforcer->setBucket( $v ); 47 | break; 48 | 49 | case 'detect-region': 50 | $bruteforcer->detectRegion(); 51 | break; 52 | 53 | case 'force-recurse': 54 | $bruteforcer->forceRecurse(); 55 | break; 56 | 57 | case 'glue': 58 | $bruteforcer->setGlue( $v ); 59 | break; 60 | 61 | case '-h': 62 | case 'help': 63 | Utils::help(); 64 | break; 65 | 66 | case 'list': 67 | $bruteforcer->disableTest(); 68 | break; 69 | 70 | case 'max-depth': 71 | $bruteforcer->setMaxDepth( $v ); 72 | break; 73 | 74 | case 'no-color': 75 | $bruteforcer->disableColor(); 76 | break; 77 | 78 | case 'perform': 79 | $bruteforcer->setTests( $v ); 80 | break; 81 | 82 | case 'permut': 83 | $bruteforcer->setPermutation( $v ); 84 | break; 85 | 86 | case 'prefix': 87 | $bruteforcer->setPrefix( $v ); 88 | break; 89 | 90 | case 'provider': 91 | $bruteforcer->setProvider( $v ); 92 | break; 93 | 94 | case 'region': 95 | if( !$bruteforcer->setRegion($v) ) { 96 | Utils::help( 'Invalid region "'.$v.'" ' ); 97 | } 98 | break; 99 | 100 | case 'suffix': 101 | $bruteforcer->setSuffix( $v ); 102 | break; 103 | 104 | case 'thread': 105 | $bruteforcer->setMaxChild( $v ); 106 | break; 107 | 108 | case '-v': 109 | case 'verbosity': 110 | $bruteforcer->setVerbosity( (int)$v ); 111 | break; 112 | 113 | default: 114 | Utils::help( 'Unknown option: '.$k ); 115 | } 116 | } 117 | 118 | if( !$bruteforcer->getBucket() ) { 119 | Utils::help( 'Bucket not found' ); 120 | } 121 | } 122 | // --- 123 | 124 | 125 | // main loop 126 | { 127 | $bruteforcer->run(); 128 | } 129 | // --- 130 | 131 | 132 | exit(); 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
93 |
94 | ---
95 |
96 | Feel free to [open an issue](/../../issues/) if you have any problem with the script.
97 |
98 |
--------------------------------------------------------------------------------
/GoogleBucket.php:
--------------------------------------------------------------------------------
1 | ssl = $https;
31 |
32 | $url = ($https ? 'https' : 'http') . '://';
33 | $url .= str_replace( '__BUCKET-NAME__', $this->name, self::BASE_URL );
34 | //if( $this->region ) {
35 | // $url = str_replace( '.digitaloceanspaces.com', '.'.$this->region.'.digitaloceanspaces.com', $url );
36 | //}
37 |
38 | return $url;
39 | }
40 |
41 |
42 | public function getName() {
43 | return $this->name;
44 | }
45 | public function setName( $v ) {
46 | $this->name = trim( $v );
47 | $this->url = str_replace( '__BUCKET-NAME__', $this->name, $this->url );
48 | $this->_url = $this->url;
49 | return true;
50 | }
51 |
52 |
53 | public function getRegion() {
54 | return $this->region;
55 | }
56 | public function setRegion( $v ) {
57 | $r = trim( $v );
58 | if( !in_array($v,self::T_REGION) ) {
59 | return false;
60 | }
61 | $this->region = $r;
62 | return true;
63 | }
64 |
65 |
66 | public function detectRegion()
67 | {
68 | /*foreach( self::T_REGION as $r )
69 | {
70 | $this->setRegion( $r );
71 |
72 | if( $this->canList(true) != 2 ) {
73 | return $r;
74 | }
75 | }*/
76 |
77 | return false;
78 | }
79 |
80 |
81 | public function exist( &$http_code=0, $redo=false )
82 | {
83 | if( is_null($this->exist) || $redo )
84 | {
85 | $c = curl_init();
86 | curl_setopt( $c, CURLOPT_URL, $this->getUrl() );
87 | curl_setopt( $c, CURLOPT_CONNECTTIMEOUT, BucketBruteForcer::REQUEST_TIMEOUT );
88 | curl_setopt( $c, CURLOPT_USERAGENT, BucketBruteForcer::T_USER_AGENT[rand(0,BucketBruteForcer::N_USER_AGENT)] );
89 | //curl_setopt( $c, CURLOPT_FOLLOWLOCATION, true );
90 | curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
91 | curl_setopt( $c, CURLOPT_NOBODY, true );
92 | //curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, false );
93 | //curl_setopt( $c, CURLOPT_HEADER, true );
94 | $r = curl_exec( $c );
95 | //var_dump( $r );
96 | $t_info = curl_getinfo( $c );
97 | //var_dump( $t_info );
98 | curl_close( $c );
99 |
100 | $http_code = $t_info['http_code'];
101 |
102 | if( $http_code == 0 )
103 | {
104 | $c = curl_init();
105 | curl_setopt( $c, CURLOPT_URL, $this->getUrl(false) );
106 | curl_setopt( $c, CURLOPT_CONNECTTIMEOUT, BucketBruteForcer::REQUEST_TIMEOUT );
107 | curl_setopt( $c, CURLOPT_USERAGENT, BucketBruteForcer::T_USER_AGENT[rand(0,BucketBruteForcer::N_USER_AGENT)] );
108 | //curl_setopt( $c, CURLOPT_FOLLOWLOCATION, true );
109 | curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
110 | curl_setopt( $c, CURLOPT_NOBODY, true );
111 | //curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, false );
112 | //curl_setopt( $c, CURLOPT_HEADER, true );
113 | $r = curl_exec( $c );
114 | //var_dump( $r );
115 | $t_info = curl_getinfo( $c );
116 | //var_dump( $t_info );
117 | curl_close( $c );
118 |
119 | $http_code = $t_info['http_code'];
120 | }
121 |
122 | $this->exist = in_array( $http_code, self::VALID_HTTP_CODE );
123 | }
124 |
125 | return $this->exist;
126 | }
127 |
128 |
129 | public function canSetAcl( $redo=false )
130 | {
131 | if( is_null($this->canSetACL) || $redo )
132 | {
133 | $cmd = "gsutil acl ch -u AllUsers:R gs://".$this->name." 2>&1";
134 | //echo $cmd."\n";
135 | exec( $cmd, $output );
136 | $output = strtolower( trim( implode("\n",$output) ) );
137 | //var_dump( $output );
138 |
139 | if( preg_match('#CommandException|AccessDeniedException#i',$output) ) {
140 | $this->canSetACL = BucketBruteForcer::TEST_FAILED;
141 | }
142 | else {
143 | $this->canSetACL = BucketBruteForcer::TEST_SUCCESS;
144 | }
145 | }
146 |
147 | return $this->canSetACL;
148 | }
149 |
150 |
151 | public function canGetAcl( $redo=false )
152 | {
153 | if( is_null($this->canGetACL) || $redo )
154 | {
155 | $cmd = "gsutil acl get gs://".$this->name." 2>&1";
156 | //echo $cmd."\n";
157 | exec( $cmd, $output );
158 | $output = strtolower( trim( implode("\n",$output) ) );
159 | //var_dump( $output );
160 |
161 | if( preg_match('#CommandException|AccessDeniedException#i',$output) ) {
162 | $this->canGetACL = BucketBruteForcer::TEST_FAILED;
163 | }
164 | else {
165 | $this->canGetACL = BucketBruteForcer::TEST_SUCCESS;
166 | }
167 | }
168 |
169 | return $this->canGetACL;
170 | }
171 |
172 |
173 | public function canList( $redo=false )
174 | {
175 | if( is_null($this->canList) || $redo )
176 | {
177 | $cmd = "gsutil ls gs://".$this->name." 2>&1";
178 | //echo $cmd."\n";
179 | exec( $cmd, $output );
180 | $output = strtolower( trim( implode("\n",$output) ) );
181 | //var_dump( $output );
182 |
183 | if( preg_match('#CommandException|AccessDeniedException#i',$output) ) {
184 | $this->canList = BucketBruteForcer::TEST_FAILED;
185 | }
186 | else {
187 | $this->canList = BucketBruteForcer::TEST_SUCCESS;
188 | }
189 | }
190 |
191 | return $this->canList;
192 | }
193 |
194 |
195 | public function canListHTTP( $redo=false )
196 | {
197 | if( is_null($this->canListHTTP) || $redo )
198 | {
199 | $c = curl_init();
200 | curl_setopt( $c, CURLOPT_URL, $this->getUrl($this->ssl) );
201 | curl_setopt( $c, CURLOPT_CONNECTTIMEOUT, BucketBruteForcer::REQUEST_TIMEOUT );
202 | //curl_setopt( $c, CURLOPT_FOLLOWLOCATION, true );
203 | curl_setopt( $c, CURLOPT_USERAGENT, BucketBruteForcer::T_USER_AGENT[rand(0,BucketBruteForcer::N_USER_AGENT)] );
204 | curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
205 | curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, false );
206 | //curl_setopt( $c, CURLOPT_HEADER, true );
207 | $r = curl_exec( $c );
208 | //var_dump( $r );
209 | $t_info = curl_getinfo( $c );
210 | //var_dump( $t_info );
211 | curl_close( $c );
212 |
213 | $http_code = $t_info['http_code'];
214 |
215 | if( $http_code == 200 ) {
216 | $this->canListHTTP = BucketBruteForcer::TEST_SUCCESS;
217 | } elseif( in_array($http_code,self::VALID_HTTP_CODE) ) {
218 | $this->canListHTTP = BucketBruteForcer::TEST_FAILED;
219 | } else {
220 | $this->canListHTTP = BucketBruteForcer::TEST_UNKNOW;
221 | }
222 | }
223 |
224 | return $this->canListHTTP;
225 | }
226 |
227 |
228 | public function canWrite( $redo=false )
229 | {
230 | if( is_null($this->canWrite) || $redo )
231 | {
232 | $cmd = "gsutil cp ".__DIR__."/test gs://".$this->name." 2>&1";
233 | //echo $cmd."\n";
234 | exec( $cmd, $output );
235 | $output = strtolower( trim( implode("\n",$output) ) );
236 | //var_dump( $output );
237 |
238 | if( preg_match('#CommandException|AccessDeniedException#i',$output) ) {
239 | $this->canWrite = BucketBruteForcer::TEST_FAILED;
240 | }
241 | else {
242 | $this->canWrite = BucketBruteForcer::TEST_SUCCESS;
243 | }
244 | }
245 |
246 | return $this->canWrite;
247 | }
248 | }
249 |
--------------------------------------------------------------------------------
/DigitaloceanBucket.php:
--------------------------------------------------------------------------------
1 | ssl = $https;
28 |
29 | $url = ($https ? 'https' : 'http') . '://';
30 | $url .= str_replace( '__BUCKET-NAME__', $this->name, self::BASE_URL );
31 | if( $this->region ) {
32 | $url = str_replace( '.digitaloceanspaces.com', '.'.$this->region.'.digitaloceanspaces.com', $url );
33 | }
34 |
35 | return $url;
36 | }
37 |
38 |
39 | public function getName() {
40 | return $this->name;
41 | }
42 | public function setName( $v ) {
43 | $this->name = trim( $v );
44 | return true;
45 | }
46 |
47 |
48 | public function getRegion() {
49 | return $this->region;
50 | }
51 | public function setRegion( $v ) {
52 | $r = trim( $v );
53 | if( !in_array($v,self::T_REGION) ) {
54 | return false;
55 | }
56 | $this->region = $r;
57 | return true;
58 | }
59 |
60 |
61 | public function detectRegion()
62 | {
63 | return $this->region;
64 | }
65 |
66 |
67 | public function exist( &$http_code=0, $redo=false )
68 | {
69 | foreach( self::T_REGION as $r )
70 | {
71 | $this->setRegion( $r );
72 |
73 | $e = $this->_exist( $http_code, true );
74 |
75 | if( $e ) {
76 | return true;
77 | }
78 | }
79 |
80 | return false;
81 | }
82 |
83 |
84 | public function _exist( &$http_code=0, $redo=false )
85 | {
86 | if( is_null($this->exist) || $redo )
87 | {
88 | $c = curl_init();
89 | curl_setopt( $c, CURLOPT_URL, $this->getUrl() );
90 | curl_setopt( $c, CURLOPT_CONNECTTIMEOUT, BucketBruteForcer::REQUEST_TIMEOUT );
91 | curl_setopt( $c, CURLOPT_USERAGENT, BucketBruteForcer::T_USER_AGENT[rand(0,BucketBruteForcer::N_USER_AGENT)] );
92 | //curl_setopt( $c, CURLOPT_FOLLOWLOCATION, true );
93 | curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
94 | curl_setopt( $c, CURLOPT_NOBODY, true );
95 | //curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, false );
96 | //curl_setopt( $c, CURLOPT_HEADER, true );
97 | $r = curl_exec( $c );
98 | //var_dump( $r );
99 | $t_info = curl_getinfo( $c );
100 | //var_dump( $t_info );
101 | curl_close( $c );
102 |
103 | $http_code = $t_info['http_code'];
104 |
105 | if( $http_code == 0 )
106 | {
107 | $c = curl_init();
108 | curl_setopt( $c, CURLOPT_URL, $this->getUrl(false) );
109 | curl_setopt( $c, CURLOPT_CONNECTTIMEOUT, BucketBruteForcer::REQUEST_TIMEOUT );
110 | curl_setopt( $c, CURLOPT_USERAGENT, BucketBruteForcer::T_USER_AGENT[rand(0,BucketBruteForcer::N_USER_AGENT)] );
111 | //curl_setopt( $c, CURLOPT_FOLLOWLOCATION, true );
112 | curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
113 | curl_setopt( $c, CURLOPT_NOBODY, true );
114 | //curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, false );
115 | //curl_setopt( $c, CURLOPT_HEADER, true );
116 | $r = curl_exec( $c );
117 | //var_dump( $r );
118 | $t_info = curl_getinfo( $c );
119 | //var_dump( $t_info );
120 | curl_close( $c );
121 |
122 | $http_code = $t_info['http_code'];
123 | }
124 |
125 | $this->exist = in_array( $http_code, self::VALID_HTTP_CODE );
126 | }
127 |
128 | return $this->exist;
129 | }
130 |
131 |
132 | public function canSetAcl( $redo=false )
133 | {
134 | return false;
135 |
136 | if( is_null($this->canSetACL) || $redo )
137 | {
138 | $cmd = "aws s3api put-bucket-acl --grant-full-control 'uri=\"http://acs.amazonaws.com/groups/global/AllUsers\"' --bucket ".$this->name." ".(strlen($this->region)?'--region '.$this->region:'')." 2>&1";
139 | //echo $cmd."\n";
140 | exec( $cmd, $output );
141 | $output = strtolower( trim( implode("\n",$output) ) );
142 | //var_dump( $output );
143 |
144 | if( preg_match('#A client error|AllAccessDisabled|AllAccessDisabled|AccessDenied#i',$output) ) {
145 | $this->canSetACL = BucketBruteForcer::TEST_FAILED;
146 | }
147 | elseif( preg_match('#An error occurred|object has no attribute#i',$output) ) {
148 | $this->canSetACL = BucketBruteForcer::TEST_UNKNOW;
149 | }
150 | else {
151 | $this->canSetACL = BucketBruteForcer::TEST_SUCCESS;
152 | }
153 | }
154 |
155 | return $this->canSetACL;
156 | }
157 |
158 |
159 | public function canGetAcl( $redo=false )
160 | {
161 | return false;
162 |
163 | if( is_null($this->canGetACL) || $redo )
164 | {
165 | $cmd = "aws s3api get-bucket-acl --bucket ".$this->name." ".(strlen($this->region)?'--region '.$this->region:'')." 2>&1";
166 | //echo $cmd."\n";
167 | exec( $cmd, $output );
168 | $output = strtolower( trim( implode("\n",$output) ) );
169 | //var_dump( $output );
170 |
171 | if( preg_match('#A client error|AllAccessDisabled|AllAccessDisabled|AccessDenied#i',$output) ) {
172 | $this->canGetACL = BucketBruteForcer::TEST_FAILED;
173 | }
174 | elseif( preg_match('#An error occurred|object has no attribute#i',$output) ) {
175 | $this->canGetACL = BucketBruteForcer::TEST_UNKNOW;
176 | }
177 | else {
178 | $this->canGetACL = BucketBruteForcer::TEST_SUCCESS;
179 | }
180 | }
181 |
182 | return $this->canGetACL;
183 | }
184 |
185 |
186 | public function canList( $redo=false )
187 | {
188 | return false;
189 |
190 | if( is_null($this->canList) || $redo )
191 | {
192 | $cmd = "aws s3api list-objects --bucket ".$this->name." --max-item 5 ".(strlen($this->region)?'--region '.$this->region:'')." 2>&1";
193 | //echo $cmd."\n";
194 | exec( $cmd, $output );
195 | $output = strtolower( trim( implode("\n",$output) ) );
196 | //var_dump( $output );
197 |
198 | if( preg_match('#A client error|AllAccessDisabled|AllAccessDisabled|AccessDenied#i',$output) ) {
199 | $this->canList = BucketBruteForcer::TEST_FAILED;
200 | }
201 | elseif( preg_match('#An error occurred|object has no attribute#i',$output) ) {
202 | $this->canList = BucketBruteForcer::TEST_UNKNOW;
203 | }
204 | else {
205 | $this->canList = BucketBruteForcer::TEST_SUCCESS;
206 | }
207 | }
208 |
209 | return $this->canList;
210 | }
211 |
212 |
213 | public function canListHTTP( $redo=false )
214 | {
215 | if( is_null($this->canListHTTP) || $redo )
216 | {
217 | $c = curl_init();
218 | curl_setopt( $c, CURLOPT_URL, $this->getUrl($this->ssl) );
219 | curl_setopt( $c, CURLOPT_CONNECTTIMEOUT, BucketBruteForcer::REQUEST_TIMEOUT );
220 | //curl_setopt( $c, CURLOPT_FOLLOWLOCATION, true );
221 | curl_setopt( $c, CURLOPT_USERAGENT, BucketBruteForcer::T_USER_AGENT[rand(0,BucketBruteForcer::N_USER_AGENT)] );
222 | curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
223 | curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, false );
224 | //curl_setopt( $c, CURLOPT_HEADER, true );
225 | $r = curl_exec( $c );
226 | //var_dump( $r );
227 | $t_info = curl_getinfo( $c );
228 | //var_dump( $t_info );
229 | curl_close( $c );
230 |
231 | $http_code = $t_info['http_code'];
232 |
233 | if( $http_code == 200 ) {
234 | $this->canListHTTP = BucketBruteForcer::TEST_SUCCESS;
235 | } elseif( in_array($http_code,self::VALID_HTTP_CODE) ) {
236 | $this->canListHTTP = BucketBruteForcer::TEST_FAILED;
237 | } else {
238 | $this->canListHTTP = BucketBruteForcer::TEST_UNKNOW;
239 | }
240 | }
241 |
242 | return $this->canListHTTP;
243 | }
244 |
245 |
246 | public function canWrite( $redo=false )
247 | {
248 | return false;
249 |
250 | if( is_null($this->canWrite) || $redo )
251 | {
252 | $cmd = "aws s3 cp ".__DIR__."/test s3://".$this->name." ".(strlen($this->region)?'--region '.$this->region:'')." 2>&1";
253 | //echo $cmd."\n";
254 | exec( $cmd, $output );
255 | $output = strtolower( trim( implode("\n",$output) ) );
256 | //var_dump( $output );
257 |
258 | if( preg_match('#A client error|upload failed|AllAccessDisabled|AllAccessDisabled|AccessDenied#i',$output) ) {
259 | $this->canWrite = BucketBruteForcer::TEST_FAILED;
260 | }
261 | elseif( preg_match('#An error occurred|object has no attribute#i',$output) ) {
262 | $this->canWrite = BucketBruteForcer::TEST_UNKNOW;
263 | }
264 | else {
265 | $this->canWrite = BucketBruteForcer::TEST_SUCCESS;
266 | }
267 | }
268 |
269 | return $this->canWrite;
270 | }
271 | }
272 |
--------------------------------------------------------------------------------
/AmazonBucket.php:
--------------------------------------------------------------------------------
1 | ssl = $https;
30 |
31 | $url = ($https ? 'https' : 'http') . '://';
32 | $url .= str_replace( '__BUCKET-NAME__', $this->name, self::BASE_URL );
33 | if( strlen($this->region) ) {
34 | $url = str_replace( 's3.amazonaws.com', 's3-'.$this->region.'.amazonaws.com', $url );
35 | }
36 | //var_dump($url);
37 |
38 | return $url;
39 | }
40 |
41 |
42 | public function getName() {
43 | return $this->name;
44 | }
45 | public function setName( $v ) {
46 | $this->name = trim( $v );
47 | $this->url = str_replace( '__BUCKET-NAME__', $this->name, $this->url );
48 | $this->_url = $this->url;
49 | return true;
50 | }
51 |
52 |
53 | public function getRegion() {
54 | return $this->region;
55 | }
56 | public function setRegion( $v ) {
57 | $r = trim( $v );
58 | if( strlen($r) && !in_array($r,self::T_REGION) ) {
59 | return false;
60 | }
61 | $this->region = $r;
62 | return true;
63 | }
64 |
65 |
66 | public function detectRegion()
67 | {
68 | foreach( self::T_REGION as $region )
69 | {
70 | $this->setRegion( $region );
71 | $this->canListHTTP( true, $r );
72 |
73 | if( stristr($r,'PermanentRedirect') && stristr($r,'The bucket you are attempting to access must be addressed using the specified endpoint') ) {
74 | $m = preg_match( '#