fbctf icon indicating copy to clipboard operation
fbctf copied to clipboard

Base functionality appears broken

Open Console opened this issue 8 years ago • 21 comments

So I've noted a few issues raised about this revolving around the autoload.php issue.

I've taken the submitted pull request and manually added the hardcoded paths as they match my current system and as a brief bodge to solve that issue but despite the scoring server offering a json format string including the team name, creating a link on each base challenge (it's a little ambiguous in the docs if one should specify protocol (e.g. http://) or just ip:port) and starting a game with active teams who share the names of the flags...

The challenges never get scored appropriately.

It's a bit late in the day here (koth competition is tomorrow) but is anyone able to offer some pointers. Other than following the modifications in the PR around languages, bases and scoring.php I'm running code freshly git pulled about 8 hours ago.

Console avatar Nov 03 '16 23:11 Console

Apologies, replace scoring.php with progressives.php above

And the pull request I refer to is pr#259

Console avatar Nov 03 '16 23:11 Console

Is this related to bases?

javuto avatar Nov 03 '16 23:11 javuto

Yes.

Console avatar Nov 04 '16 06:11 Console

So looking a little further this morning:

// Get the IP from a base level. public static async function genBaseIP(int $base_id): Awaitable { $links = await Link::genAllLinks($base_id); $link = $links[0]; $ip = explode(':', $link->getLink())[0];

return $ip;

}

// Request all bases public static function getBasesResponses( array<int, array<string, mixed>> $bases, ): array<int, string> { // Iterates and request all the bases endpoints for owner $responses = array(); $curl_handlers = array(); $multi_handler = curl_multi_init();

// Create the list of request handlers
foreach ($bases as $base) {
  $base_id = intval(must_have_idx($base, 'id'));
  $base_url = must_have_idx($base, 'url');
  $curl_handlers[$base_id] = curl_init();
  curl_setopt($curl_handlers[$base_id], CURLOPT_URL, $base_url);
  curl_setopt($curl_handlers[$base_id], CURLOPT_HEADER, 0);
  curl_setopt($curl_handlers[$base_id], CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl_handlers[$base_id], CURLOPT_PORT, 12345);
  curl_setopt($curl_handlers[$base_id], CURLOPT_TIMEOUT, 3);
  curl_multi_add_handle($multi_handler, $curl_handlers[$base_id]);

Appears to hard set the port to 12345. The genBaseIP function strips the port and throws it out of the window, while the curlopt_port hard sets it to 12345, this doesn't work for my scenario in particular but the documentation for this also suggests that the port is "settable" via the link attribute.

Any ideas anyone? Even if the base python script is running on 12345, no traffic is seen from the fbctf server to the flag server, so it doesn't appear like CURL is actually being run regardless.

Console avatar Nov 04 '16 08:11 Console

check #326

inche-ali avatar Nov 04 '16 09:11 inche-ali

Checked it. Interesting info. Will leave it 5 minutes next time I test it this weekend however I'm 99% sure this has never worked.

Why is the port hardcoded? The ip is obtained from the link and the port segment is discarded, seems pretty trivial to just support custom ports.

My use case was a little odd granted...

I'd already asked folk to design levels for a king of the hill competition.

Discovered fbctf and liked it. However levels were built having the flag hosted on a webserver per each machine (allowing anyone to use any OS they liked so long as they served the flag via http)

So I modified the base script to fetch a URL and read the response as the team name. It fed into the rest of the example script and the correct json output produced.

I ran multiples of these scripts (1 for each flag) on the fbctf server. So the link for each would have been one in the range of 127.0.0.1:10001 to 127.0.0.1:10022.

Sadly the hardcoded port and lack of documentation regarding the scoring timer lead to confusion on my part.

There is a progressive and base scoring timer set in seconds within the admin configuration interface, what do these do if scoring is hard set to 5 minutes?

I'm not a github guru nor familiar with hhvm or python I can google-code with the best of them as needed but appreciate some help here making the above achievable :)

The port seems easy enough, I just grab the [1] of the exploded string but the timer and daemon... Where on earth would I start to look to modify there?

Console avatar Nov 04 '16 22:11 Console

I have also had issues with this. #169

jeszicawii avatar Nov 14 '16 13:11 jeszicawii

I have also had an issue with this. Couldn't it be a JSON request to the first link you provide? I want to be able to specify http/https and which page on the url

Akm0d avatar Mar 08 '17 19:03 Akm0d

I am also having this issue. I've run packet captures on both the fbctf server and the "base" and don't see fbctf trying to check the base for an updated score.

myearsley avatar Apr 03 '17 17:04 myearsley

Has this ever been resolved? I'm having a really hard time getting this working, and as far as I can tell the fbctf server never actually checks the base to see if it's been taken

TheSeraph avatar Oct 18 '17 12:10 TheSeraph

I figured it out...you have to activate the game...I think I wasn't scrolling down on the menu and didn't see the activate button. If the timer isn't going the game isn't started. If you don't start the game FBCTF won't check the base.

myearsley avatar Oct 19 '17 00:10 myearsley

Are you sure? I've got a base setup, and the game has begun, You can score points elsewhere (quizzes and such). It seems to check bases when the game starts, but never checks them again afterwards.

TheSeraph avatar Oct 19 '17 09:10 TheSeraph

So I've gone back and tested this a few ways. It looks like when the game starts, checking bases works. However, after the first base is captured (any base) the check stops working, and then no other bases can be capture, nor can the original base be captured.

I've tested this by setting up two bases in my config, and resetting the game multiple times, capturing them in different order with different teams. Does anybody have an idea why bases stop being checked after the initial pass?

TheSeraph avatar Oct 19 '17 10:10 TheSeraph

@TheSeraph

Can you confirm if the bases.php script is still running after a capture? If not, was there any error in the HHVM error log?

justinwray avatar Oct 23 '17 16:10 justinwray

I feel dumb asking this, but how would I be able to check/confirm that?

TheSeraph avatar Oct 23 '17 18:10 TheSeraph

@TheSeraph

No problem. The platform will execute a number of HHVM processes, running various HHVM scripts. One of those is used to score the bases: /scripts/bases.php

You can find a list of the various HHVM processes, including the bases.php script, by running a command via console on the HHVM/platform server, such as:

ps aux | grep "bases"

This script must be running for the bases to be scored.

justinwray avatar Oct 23 '17 18:10 justinwray

Sorry for the delay in response. So I've done that and looked into the error log. After a base is scored upon by a team, the script does indeed stop running, I've noticed that if I pause/unpause it has a similar affect of restarting the bases.php script, however, even if another team takes a base it will not update any points.

I've been live-tailing the error log (/var/log/hhvm/error.log) although I'm not sure if it's the right one. I can only see a few weird things every now and then, but they don't seem to correlate with my actions,

[Mon Oct 23 19:56:49 2017] [hphp] [1389:7f45ddbff700:38391:000001] [] #0 /var/www/fbctf/src/Router.php(77): SessionUtils::enforceLogin()\n#1 /var/www/fbctf/src/Router.php(20): Router::genRouteNormal()\n#2 /var/www/fbctf/src/index.php(7): Router::genRoute()\n#3 (): genInit()\n#4 /var/www/fbctf/src/index.php(17): HH\\Asio\\join()\n#5 {main}

I also see a lot of warnings about translations not being available, but I suspect that's because my browser is in an unsupported language. Is this helpful?

TheSeraph avatar Oct 23 '17 20:10 TheSeraph

@TheSeraph

Thank you yes that is helpful. The script shouldn't stop, and the error you referenced is from an unauthenticated account (so unrelated in this case). I'll mark this as a bug and we will have a look.

justinwray avatar Oct 23 '17 21:10 justinwray

I've reinstalled this on another server. It should be said I've tested this with Standard Single Server Prod (non-vagrant, non-container). I've observed much the same behaviour. I checked the log since there shouldn't be much on a fresh install and saw:

[Fri Oct 27 07:29:48 2017] [hphp] [5049:7f3ac67ff700:12:000002] [] \nFatal error: Uncaught exception 'HH\\InvariantException' with message 'Failed to set attachment file permissions to 0600' in /var/www/fbctf/src/models/Control.php:437\nStack trace:\n#0 /var/www/fbctf/src/models/Control.php(437): HH\\invariant_violation()\n#1 /var/www/fbctf/src/controllers/ajax/AdminAjaxController.php(509): Control::importAttachments()\n#2 /var/www/fbctf/src/controllers/ajax/AjaxController.php(14): AdminAjaxController->genHandleAction()\n#3 /var/www/fbctf/src/Router.php(58): AjaxController->genHandleRequest()\n#4 /var/www/fbctf/src/Router.php(14): Router::genRouteAjax()\n#5 /var/www/fbctf/src/index.php(7): Router::genRoute()\n#6 /var/www/fbctf/src/index.php(17): genInit()\n#7 {main}

Don't know if that's helpful. I tried to see if bases.php was running, and as on the previous server, it's not after the first base is captured. I also tested this on the single server dev, with the same results. Additionally I note that restarting nginx or hhvm does nothing. Only starting and stopping the game has a limited effect.

Another clue might be that when a base is capture, the "activity log" on the gameboard isn't updated, even though the "GAME LOGS TIMELINE" in the backend IS udpated.

TheSeraph avatar Oct 27 '17 08:10 TheSeraph

I know I'm late to the party, but has anyone been able to get the Base functionality working?

FWSquatch avatar Jan 23 '18 13:01 FWSquatch

I don't know if it fixes it in all cases, but the autorun script attempts to reference the server's DOCUMENT_ROOT, which doesn't exist in the background scripts. This means it attempts to execute /scripts/bases.php rather than /var/www/fbctf/src/scripts/bases.php. I've fixed it, and added logging & some resilience in #634.

JasonTarka avatar Mar 27 '18 20:03 JasonTarka