Skip to content

Instantly share code, notes, and snippets.

@q3w3e3
Created January 16, 2026 01:32
Show Gist options
  • Select an option

  • Save q3w3e3/2c7809fa92c75c9cac9ca37ef5696ad7 to your computer and use it in GitHub Desktop.

Select an option

Save q3w3e3/2c7809fa92c75c9cac9ca37ef5696ad7 to your computer and use it in GitHub Desktop.
omg, hi yall, ive finally got round to my bggp6 entry!!! :cat_XD::cat_3nod:
[code][/code]
:angelleft::cat_ninja::angelright: yoinking an idea from [url=https://github.com/binarygolf/BGGP/tree/main/2024/entries/Luna%20Hart]Luna Hart's BGGP5 submission[/url], I started with a just a pure clone of here submission... a file named `curl -L binary.golf --request-target 5%2f5` with contents:
[code]$0[/code]
(Side Note: she and i were working this out together (all credit to her tho) a couple years ago when that was the challenge, i was desperate to make using the filename to work with wget's args, she got it working with curl... im still sad i never got it playing nice with wget... this isnt my redemption... instead im continuing to leach off her better solution!)
i couldn't really do more shorter [i]and[/i] i wasn't satisfying the constraint "Files must also print, return, or otherwise display the value "6" for identification when opened or executed". i could achieve this by simply echoing 6 and moving on, but that doesnt get me more bonus points!
:angelleft: so lets look at the other easy to achieve in bash challenges, and where i could return a 6... can i crash in a way that returns a 6 and is short? probably, but i dont know how and `kill -11 $$` is only 11 chars and gets me the bonus points for a crash, maybe i can return/print/whatever a 6 elsewhere? but thats a good start, i can now add the chunk:
[code];kill -11 $$[/code]
:angelleft: self replication! that's also super easy _and_ i can just write it to a file of name 6.... does this file execute how i want? no.... it doesnt have the right filename, and the filename is important... but... the rules for bggp4 called out ` - Name the copy "4" `, so naming the file something new appears to be fair game. this should be easy enough... i have my "execute the filename" `$0` and `;kill -11 $$`, lets just shove something between them to take the contents of $0, and put it into a file named 6.
my initial run at this used `cat "$0" > 6`, but i realized that i can just copy files.... i dont need to print their contents and redirect that to a new file, so i settled on using cp, saving me 3 bytes, and giving me the final chunk of the puzzle:
[code]cp "$0" 6[/code]
:angelleft: so in the end we have a file which is named `curl -L binary.golf --request-target 5%2f5` and has contents of
[quote][code]$0;cp "$0" 6;kill -11 $$[/code][/quote]
:angelleft: another thing to save a byte was remembering to strip the linefeed off the end of the file... thanks $texteditor
when executed will download a file, copy its contents to a new file named 6, and then kill itself with a SIGSEGV. This achieves:
[quote]BGGP6: print, return, or otherwise display the value "6" for identification when opened or executed
BGGP5: download a file
BGGP4: self replicating
BGGP3: crash[/quote]
[align=center] :wahmbulance: :cat_idea: 2025-01-15 UPDATE :cat_idea: :wahmbulance: [/align]
:nitemareleft: i can make this a polyglot! :nitemareright:
easiest way to make a polyglot is to make one of the lang just call the other lang with the existing payload AND not break execution in the original lang. the first part is trivial, i could wrap it in `system()` or `exec()` BUT these break my bash, i [i]believe[/i] because of the parens breaking the args (subshells and their consequences...)
:angelleft: instead i will use backticks! which in perl will execute a system command (shell!) and in the shell will do command substitution. This looks like exactly what i want!
lets run it:
[quote][code]
bggp6 %xxd curl -L binary.golf --request-target 5%2f5
00000000: 6024 303b 6370 2022 2430 2220 363b 6b69 `$0;cp "$0" 6;ki
00000010: 6c6c 202d 3131 2024 2460 ll -11 $$`
bggp6 %sh curl -L binary.golf --request-target 5%2f5
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 162 100 162 0 0 765 0 --:--:-- --:--:-- --:--:-- 764
100 58 100 58 0 0 151 0 --:--:-- --:--:-- --:--:-- 151
zsh: segmentation fault sh curl -L binary.golf --request-target 5%2f5
bggp6 %
[/code][/quote]
[size=18] FRICK! :cat_crying: [/size]
we no longer meet the requirement for the download challenge "Display the file's contents in some way"... now, im gonna stretch this a little, and take writing to a file as a type of "display"... but thats better than "i showed you a progress bar...".
so, its not quite as easy as "lets wrap it in backticks", but this is solvable, theres plenty of ways to make curl put the file Somewhere instead of to stdout. I have settled on just naming the file [code]curl -L binary.golf --request-target 5%2f5 -O[/code]
executed this will look like:
[quote][code]
bggp6_2 %xxd curl -L binary.golf --request-target 5%2f5 -O
00000000: 6024 303b 6370 2022 2430 2220 363b 6b69 `$0;cp "$0" 6;ki
00000010: 6c6c 202d 3131 2024 2460 ll -11 $$`
bggp6_2 %sh curl -L binary.golf --request-target 5%2f5 -O
Warning: No remote file name, uses "curl_response"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 162 100 162 0 0 3486 0 --:--:-- --:--:-- --:--:-- 3521
100 58 100 58 0 0 513 0 --:--:-- --:--:-- --:--:-- 513
zsh: segmentation fault sh curl -L binary.golf --request-target 5%2f5 -O
bggp6_2 %cat curl_response
Another #BGGP5 download!! @binarygolf https://binary.golf
bggp6_2 %sha256sum 6 curl -L binary.golf --request-target 5%2f5 -O
ef549a7ccfe5af10910a6cafae7ad32b1e5e14f2bc40a4604d1ec86d1ba53a5e 6
ef549a7ccfe5af10910a6cafae7ad32b1e5e14f2bc40a4604d1ec86d1ba53a5e curl -L binary.golf --request-target 5%2f5 -O
[/code][/quote]
[align=center]:pawstamp:bonus!:pawstamp:[/align]
and as a little bonus, i feel a little weird dumping a reasonable amount of the payload into the filename, so heres how i have done it without using `$0` to hold any payload:
:angelleft: lets start by just naively replacing the first $0 with the filename, and renaming the file something generic like bggp6. This does work, you can view the execution as above here if you dont want to just take my work for it:
[spoiler][code]
bggp6_3 %xxd bggp6
00000000: 6063 7572 6c20 2d4c 2062 696e 6172 792e `curl -L binary.
00000010: 676f 6c66 202d 2d72 6571 7565 7374 2d74 golf --request-t
00000020: 6172 6765 7420 3525 3266 3520 2d6f 353b arget 5%2f5 -o5;
00000030: 6370 2022 2430 2220 363b 6b69 6c6c 202d cp "$0" 6;kill -
00000040: 3131 2024 2460 11 $$`
bggp6_3 %sh bggp6
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 162 100 162 0 0 3138 0 --:--:-- --:--:-- --:--:-- 3176
100 58 100 58 0 0 461 0 --:--:-- --:--:-- --:--:-- 461
zsh: segmentation fault sh bggp6
bggp6_3 %cat 5
Another #BGGP5 download!! @binarygolf https://binary.golf
bggp6_3 %sha256sum 6 bggp6
77369526e278675d880b25bbdf6c5359847b621de8c7279af00da41bfb17a9cc 6
77369526e278675d880b25bbdf6c5359847b621de8c7279af00da41bfb17a9cc bggp6
bggp6_3 %rm 5 6
bggp6_3 %perl bggp6
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 162 100 162 0 0 2810 0 --:--:-- --:--:-- --:--:-- 2842
100 58 100 58 0 0 436 0 --:--:-- --:--:-- --:--:-- 436
zsh: segmentation fault perl bggp6
bggp6_3 %cat 5
Another #BGGP5 download!! @binarygolf https://binary.golf
bggp6_3 %sha256sum 6 bggp6
77369526e278675d880b25bbdf6c5359847b621de8c7279af00da41bfb17a9cc 6
77369526e278675d880b25bbdf6c5359847b621de8c7279af00da41bfb17a9cc bggp6
bggp6_3 %
[/code]
pls ignore that i use -o5 here instead of -O, we can save one byte...
[/spoiler]
but its LONG! its a whole 69 (nice) bytes now!!!
:angelleft: lets remove some extraineos stuff, we shouldnt need the `--request-target 5%2f5` stuff that had to be done to get the curl in filename working, so lets write a more normal curl of the url.
[code]`curl -L binary.golf/5/5 -O;cp "$0" 6;kill -11 $$`[/code]
down to 50 bytes
this is okay, but its a pain that we still need that -L to traverse the 301 permenant redirect... but now that we arent dealing with restrictions on what can be in a filename, maybe we can go back to wget!
[code]`wget binary.golf/5/5;cp "$0" 6;kill -11 $$`[/code]
44 bytes, and i think thats where im going to call it for this.
love you all, be good to each other, take care out there!
q3w3e3
User Comments: [1]
want to see my submissions?
check them out here:
- original: https://github.com/binarygolf/BGGP/issues/169
- polyglot: https://github.com/binarygolf/BGGP/issues/171
- No args: https://github.com/binarygolf/BGGP/issues/172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment