Reversing

obfuscJStor

Description :
Obfuscated JavaScript?? Really??

Attached file : [obfuscJStor.js]
function _0x12de(){var _0x6ab222=['\x2e\x69\x6f','\x75\x73\x63\x61\x74','\x37\x32\x4f\x4f\x6e\x7a\x73\x4d','\x61\x5f\x74\x6f\x6f','\x6c\x6f\x67','\x62\x79\x75\x63\x74','\x32\x30\x35\x38\x31\x31\x31\x56\x73\x4a\x6d\x4e\x74','\x64\x61\x79\x73\x5f','\x35\x62\x6b\x68\x53\x6b\x77','\x36\x32\x37\x38\x77\x53\x77\x45\x56\x49','\x31\x32\x35\x33\x31\x33\x30\x78\x4e\x74\x74\x57\x77','\x48\x6d\x6d\x6d\x6d','\x6c\x5f\x74\x6f\x5f','\x77\x68\x65\x72\x65','\x66\x6c\x61\x67\x20','\x34\x31\x30\x35\x39\x34\x34\x58\x71\x67\x53\x54\x64','\x31\x30\x69\x47\x78\x53\x78\x74','\x35\x33\x4d\x50\x56\x43\x43\x73','\x63\x61\x74\x6f\x72','\x6d\x61\x6b\x65\x5f','\x6f\x62\x66\x75\x73','\x32\x35\x34\x30\x30\x39\x74\x71\x59\x51\x79\x6b','\x35\x31\x30\x35\x30\x31\x46\x57\x64\x52\x56\x71','\x66\x7b\x6f\x6e\x65','\x64\x65\x6f\x62\x66','\x68\x65\x73\x65\x5f','\x5f\x6f\x66\x5f\x74','\x31\x37\x32\x36\x34\x35\x6f\x6b\x76\x58\x66\x70','\x69\x73\x3f','\x34\x6d\x6f\x71\x49\x6c\x56'];_0x12de=function(){return _0x6ab222;};return _0x12de();}(function(_0x2a4cef,_0x9e205){var _0x539a11=_0x2a7d,_0x40cc8a=_0x2a4cef();while(!![]){try{var _0x2d47a2=-parseInt(_0x539a11(0x1f1))/0x1*(-parseInt(_0x539a11(0x207))/0x2)+parseInt(_0x539a11(0x1f6))/0x3*(parseInt(_0x539a11(0x1fd))/0x4)+-parseInt(_0x539a11(0x206))/0x5*(-parseInt(_0x539a11(0x208))/0x6)+-parseInt(_0x539a11(0x1f5))/0x7*(parseInt(_0x539a11(0x200))/0x8)+parseInt(_0x539a11(0x204))/0x9*(-parseInt(_0x539a11(0x1f0))/0xa)+parseInt(_0x539a11(0x1fb))/0xb+parseInt(_0x539a11(0x1ef))/0xc;if(_0x2d47a2===_0x9e205)break;else _0x40cc8a['push'](_0x40cc8a['shift']());}catch(_0x4063a2){_0x40cc8a['push'](_0x40cc8a['shift']());}}}(_0x12de,0x54f50));function _0x2a7d(_0x339bb1,_0x1a0657){var _0x12def3=_0x12de();return _0x2a7d=function(_0x2a7d9a,_0x2b9202){_0x2a7d9a=_0x2a7d9a-0x1ee;var _0x34fb38=_0x12def3[_0x2a7d9a];return _0x34fb38;},_0x2a7d(_0x339bb1,_0x1a0657);}function hi(){var _0x398601=_0x2a7d;document['\x64\x6f\x6d\x61\x69'+'\x6e']==_0x398601(0x1f4)+_0x398601(0x1f2)+_0x398601(0x1fe)&&console[_0x398601(0x202)](_0x398601(0x203)+_0x398601(0x1f7)+_0x398601(0x1fa)+_0x398601(0x1f9)+_0x398601(0x205)+'\x69\x6d\x6d\x61\x5f'+_0x398601(0x1f3)+_0x398601(0x201)+_0x398601(0x20a)+_0x398601(0x1f8)+_0x398601(0x1ff)+'\x65\x5f\x74\x68\x69'+'\x73\x7d'),console['\x6c\x6f\x67'](_0x398601(0x209)+'\x20\x49\x20\x77\x6f'+'\x6e\x64\x65\x72\x20'+_0x398601(0x20b)+'\x20\x74\x68\x65\x20'+_0x398601(0x1ee)+_0x398601(0x1fc));}hi();
  • 지저분하게 난독화 된 js 파일이 주어졌다.

문제 풀이

전에 다른 CTF에서 난독화 해제가 됐었던 거 같기도 하고… 문제 이름에서 힌트를 얻어 검색하여 관련된 난독화하는 Tool 페이지를 찾았다.


해당 페이지에서는 난독화만 진행이 되는 것 같아, 난독화를 해제가 가능한 곳이 있는지 더 찾아보다가 해제가 되는 사이트를 찾아냈다.


난독화 해제 후 코드

'use strict';  
function _0x12de() {  
 var functionNames = [".io", "uscat", "72OOnzsM", "a_too", "log", "byuct", "2058111VsJmNt", "days_", "5bkhSkw", "6278wSwEVI", "1253130xNttWw", "Hmmmm", "l_to_", "where", "flag ", "4105944XqgSTd", "10iGxSxt", "53MPVCCs", "cator", "make_", "obfus", "254009tqYQyk", "510501FWdRVq", "f{one", "deobf", "hese_", "_of_t", "172645okvXfp", "is?", "4moqIlV"];  
 _0x12de = function findFunctionNames() {  
   return functionNames;  
 };  
 return _0x12de();  
}  
(function(saveNotifs, y) {  
 var toMonths = _0x2a7d;  
 var keymod = saveNotifs();  
 for (; !![];) {  
   try {  
     var swipingDirection = -parseInt(toMonths(497)) / 1 * (-parseInt(toMonths(519)) / 2) + parseInt(toMonths(502)) / 3 * (parseInt(toMonths(509)) / 4) + -parseInt(toMonths(518)) / 5 * (-parseInt(toMonths(520)) / 6) + -parseInt(toMonths(501)) / 7 * (parseInt(toMonths(512)) / 8) + parseInt(toMonths(516)) / 9 * (-parseInt(toMonths(496)) / 10) + parseInt(toMonths(507)) / 11 + parseInt(toMonths(495)) / 12;  
     if (swipingDirection === y) {  
       break;  
     } else {  
       keymod["push"](keymod["shift"]());  
     }  
   } catch (_0x4063a2) {  
     keymod["push"](keymod["shift"]());  
   }  
 }  
})(_0x12de, 347984);  
function _0x2a7d(totalExpectedResults, entrySelector) {  
 var tiledImageBRs = _0x12de();  
 return _0x2a7d = function searchSelect2(totalExpectedResults, entrySelector) {  
   totalExpectedResults = totalExpectedResults - 494;  
   var tiledImageBR = tiledImageBRs[totalExpectedResults];  
   return tiledImageBR;  
 }, _0x2a7d(totalExpectedResults, entrySelector);  
}  
function hi() {  
 var log = _0x2a7d;  
 if (document["domai" + "n"] == log(500) + log(498) + log(510)) {  
   console[log(514)](log(515) + log(503) + log(506) + log(505) + log(517) + "imma_" + log(499) + log(513) + log(522) + log(504) + log(511) + "e_thi" + "s}");  
 }  
 console["log"](log(521) + " I wo" + "nder " + log(523) + " the " + log(494) + log(508));  
}  
hi();
  • 난독화를 해제하고 나니 뭔가 좀 더 읽을 수 있을 거 같고… 더 이뻐졌다;;


함수들을 한번 눈으로 쭉 훑어본 뒤, 개발자도구 Console에서 해당 코드를 실행시켜 보았다.


obfuscJStor-2


obfuscJStor-3

함수 실행 결과를 보고, 코드를 보니, 맨 위에 functionNmae 배열에 임의의 문자들과 flag가 잘리고 섞여 들어있고, 중간 함수에선 특정 연산들이 있으며, 하단의 if을 통해 flag가 찍히거나, 아니면 'Hmmmm I wonder where the flag is?'를 만들어서 출력되는 거 같았다.

일단 제일 쉬운 방법인 if문 조건을 반대로 변경 후 다시 실행해보았다.

obfuscJStor-5

  • flag 출력 확인

안 나왔으면 함수 다 뜯어볼 뻔했는데 운이 좋았다. flag 획득!

Crypto

RSA-1

Description :

Attached file : [rsa1.txt]
n = 287838647563564518717519107521814079281
e = 7
c = 258476617615202392748150555415953446503


image

http://www.factordb.com/에서 확인한 p, q값을 넣어 python 코드를 작성한다.


from Crypto.Util.number import *
n = 287838647563564518717519107521814079281
e = 7
c = 258476617615202392748150555415953446503

p = 15631612382272805561
q = 18413880828441662521

phi = (p-1)*(q-1)
d = pow(e,-1,phi)
m = pow(c,d,n)

print(long_to_bytes(m).decode())


image

  • flag 확인

RSA-2

Description :

Attached file : [rsa2.txt]
n = 546014635841741214724882952304387823741798461149589549073179989118942746109940806878269775538274570065946589413677004071487344751464649121103982272835006900203922112014630898761428602513684456008956735791010937229939856259403186940249737579526542460562078728957198932156520780835942292131829398548678970431263462917223085165930683353518778015361505451889259321493813123084031407195410778661720394898118828299025325200597986154170392835072784810370185329392356423340408483449291280713796374297147668615988522804223480631576577707073715128342533703842150980913675658012799681575774731843549389349977365287936534707998476564357339504431638612839358093914282814270477657856345062084136585402704930924062452984009716927826681976269057923158930326380110735873715506666086031427627450725825495228912040943784627278987497908133546573083543604901933763330940965980882566819970423354937076331119777415405707162588442490342746115310986462330781467571631209829523895479737199963129517613642920935109776495829400236613168913129178658637967592913193540283532220304664924612246117951571439486418122093867454452618997458068515332016877486822805232899716524040444751997121936138984564834862354469295078855441829018404782747219665338778379471257704041

e = 65537

c = 497483520135207500611760341868934810216889295862727367409205471739457798733223813938415492642898622071289502771394670201759355356873731071744923938304067196827981196823596976532284031567818944043351160692892539254848854527943095670705184836531463778923699513154523281624336593518751911469590777921172775020125081803529411082078530404614569485860638460689961289946436553586222781503048987585305336865777424252321433817251942278548031598867440246798562662298880488044382840476214732326114298681849826143159014132251265975612736174765852107701466877003101250308950535660691651846052082123375934624356694170453897672257371991315676787548733520567289929667876604682273501711766130944645562650989837328685043543330211830184365436596077862055649246517141787872170320358968622818470064395975654949073402489903952399985907827496667385839890041608685588908200009780210043116940593521695695047783434230143405184690206691002634954008353327872663055826018481013718627348218684688250775372760462829705754318024652361552668830110066219305953343851243676904796434142570868419087560131333056695456062994781034014322792678534785191950145702468201676105282230660132801024614625267740668507168119879074770666830923799616054485447308126877109671082189614


image

http://www.factordb.com/에서 확인한 p, q값을 넣어 python 코드를 작성한다.


from Crypto.Util.number import *
n = 546014635841741214724882952304387823741798461149589549073179989118942746109940806878269775538274570065946589413677004071487344751464649121103982272835006900203922112014630898761428602513684456008956735791010937229939856259403186940249737579526542460562078728957198932156520780835942292131829398548678970431263462917223085165930683353518778015361505451889259321493813123084031407195410778661720394898118828299025325200597986154170392835072784810370185329392356423340408483449291280713796374297147668615988522804223480631576577707073715128342533703842150980913675658012799681575774731843549389349977365287936534707998476564357339504431638612839358093914282814270477657856345062084136585402704930924062452984009716927826681976269057923158930326380110735873715506666086031427627450725825495228912040943784627278987497908133546573083543604901933763330940965980882566819970423354937076331119777415405707162588442490342746115310986462330781467571631209829523895479737199963129517613642920935109776495829400236613168913129178658637967592913193540283532220304664924612246117951571439486418122093867454452618997458068515332016877486822805232899716524040444751997121936138984564834862354469295078855441829018404782747219665338778379471257704041
e = 65537
c = 497483520135207500611760341868934810216889295862727367409205471739457798733223813938415492642898622071289502771394670201759355356873731071744923938304067196827981196823596976532284031567818944043351160692892539254848854527943095670705184836531463778923699513154523281624336593518751911469590777921172775020125081803529411082078530404614569485860638460689961289946436553586222781503048987585305336865777424252321433817251942278548031598867440246798562662298880488044382840476214732326114298681849826143159014132251265975612736174765852107701466877003101250308950535660691651846052082123375934624356694170453897672257371991315676787548733520567289929667876604682273501711766130944645562650989837328685043543330211830184365436596077862055649246517141787872170320358968622818470064395975654949073402489903952399985907827496667385839890041608685588908200009780210043116940593521695695047783434230143405184690206691002634954008353327872663055826018481013718627348218684688250775372760462829705754318024652361552668830110066219305953343851243676904796434142570868419087560131333056695456062994781034014322792678534785191950145702468201676105282230660132801024614625267740668507168119879074770666830923799616054485447308126877109671082189614

p = 23354146979807319379999035616961227366315140956417473671454187034894451162291754802462941941792796900830979379875976598091266482784685424013905480696388873312112449447015212036533336920764065285748033710474328055812364692120325949818178301777905279103958955246642416286153474237338739835798119305508201074075918506331902107847659951627678483765213310235851319160745426496852724170929530989982548624157909773262752522594414435161921211944019434983046703898010646693649668494220236993757035493132421299985405030215783112721654976457363937286689672094963265015048673356916456174809392166143308820305157390154213277022361

q = 23379772179812068808174060753537744579203831235837216258047345717791206838844783973094148970269358352883567686183840162453475135997997950171025172534250066839781721720291637394109275750765747393807129441718738564581300844549866075387635571271298099970059805382997224172143494300775742278526976057440901844970233807992493192827375594281731619879000721912671268883932814086571959959837609600236134071446484378655039534937911808777812990351810838102078057859303673209338100518315299313874836179635779981742550281014611235035038725280128727341135995530457136512443488805309366834219571741391932893715725604175334445964881

phi = (p-1)*(q-1)
d = pow(e,-1,phi)
m = pow(c,d,n)

print(long_to_bytes(m).decode())


image

  • flag 확인

RSA-3

Description :

Attached file : [rsa3.txt]
n1 = 26936730986023789726214222876998431579035871765812234385674097050592112272540329063679602773116293498245937781951160051718036177035087801218359133356523071700951108999020905116034905584806261203518345118128714311038590925635180342040347317022008233631809623824589107373210514331169745651687793393307158179191306187356408951648269495142386375021669218752561961647301029204701333026044435685936341126368602940601101599988477874713569476970068734357580527463645209944448988010693985476127837819331701523891965427561798033127731232916390511986369304971158889254173850566560028528340860519614489276904182246324437302697433

e1 = 65537

c1 = 25934221721388531303090294836956821212346696995428676440185777623629033147440636130540319272854260855117016879903925227836710795492438220977864741830686432435183222727791461378988782191893620213711460265022633971293289987925875691438890670054518553696690583070284033592035281829227897938832962322172505881421894428362134145126751766514249801481330619906708370005958557827981820321861133293595400304305721764486699677941331024345924352161482159664366018182446127343098427579677894070842066840562853624060861183697917208697602208453017595582242281467105778066369782229287834403074433848470534633158573935584429007575715


n2 = 20923351960149847207730448386993771286287991808293298691185156471519720793292179321382926775933281826329369963004005667653815105072159583791658532166606431385861980687037872135521884790087813454844716254644626942821490878728677736261700329782075809716063515721266692286574071240561529911159730824490258866613280873755548760004314650585913096197607936750263556276920577987540676841745347308103070523989154846358123142014592046611945781700690640990848003152423310523158983857208127158850925297742214928064334410930947749935069628731105093722212442331657106356911123912454871778728334875010902513275561639806401894881233

e2 = 65537

c2 = 5993773597007465934515223705550947500391213737662065644971977783446564890828050443747162704068048188331597029929182281837445674583301936037963788912954366180921337518251139032904603786774772009913305609053718347365864177247549192649908207240197602397010006677485658506955283638199651692990436006544549785434255965098715363287267470252318128158357490592521797199393154974403123099999366644663048724011101287811844340320520544010179529188112211115440469084617438296961494801221969674213288489675624156545941630517075958425681203711654677553772595530799489102830165490202523397154229276688719481530893488434863906070343


n1,n2,e1,e2,c1,c2를 준 것을 보니, 다른 취약점이 있는 듯 하였으나, factordb에서 풀렸으므로 동일하게 코드를 작성하였다. http://www.factordb.com/에서 확인한 p, q값을 넣어 python 코드를 작성한다.


image


from Crypto.Util.number import *
n = 26936730986023789726214222876998431579035871765812234385674097050592112272540329063679602773116293498245937781951160051718036177035087801218359133356523071700951108999020905116034905584806261203518345118128714311038590925635180342040347317022008233631809623824589107373210514331169745651687793393307158179191306187356408951648269495142386375021669218752561961647301029204701333026044435685936341126368602940601101599988477874713569476970068734357580527463645209944448988010693985476127837819331701523891965427561798033127731232916390511986369304971158889254173850566560028528340860519614489276904182246324437302697433
e = 65537
c = 25934221721388531303090294836956821212346696995428676440185777623629033147440636130540319272854260855117016879903925227836710795492438220977864741830686432435183222727791461378988782191893620213711460265022633971293289987925875691438890670054518553696690583070284033592035281829227897938832962322172505881421894428362134145126751766514249801481330619906708370005958557827981820321861133293595400304305721764486699677941331024345924352161482159664366018182446127343098427579677894070842066840562853624060861183697917208697602208453017595582242281467105778066369782229287834403074433848470534633158573935584429007575715

p = 158954135912536259649845552382757849078339820320889922784576644780347102092039759071735700930458068125729993437629627127489937677182234654634528546796102749001441786797851584837364751075271572884183286900728332748215222105328915933271749659017999737220238175387228902907641858812820949035828633637080555842217

q = 169462284396585911849574285651271443371876901092320858398545983156942539436929846404404679656482378298122786540995721429096585253848180086811629361617206413459150016149567031889102951830833040736468496796020866541776202762448423458853776925394946588441545505005536816213547053664824743158608813965992840726449

phi = (p-1)*(q-1)
d = pow(e,-1,phi)
m = pow(c,d,n)

print(long_to_bytes(m).decode())


image

  • flag 확인

RSA-4

Description :

Attached file : [rsa4.txt]
n1 = 25204912957894049536633029588071532883154221495361435745558539407530325536509218257991893451902442183954212400671502526830623527340613723328379300388737939211263541814108106183164630301938900862986688763583982133846507136234797325243547177627054271161715200611591594812723672399437505379398941496184886411879923583394041753902383846644013849190900416111230521180435101859101110596828380586449182686175177638441549656137307050392520754146511496313215137339773851458160180450925216541537448515297981124184019831730808991821344392915274230294654187421183676471212265322367890189804699510021526923237231850244056681024361

e1 = 3

c1 = 8177192204481601898705460379101384591996531766013815643642297541939314169289538943467463950155787562006058743758523755363825964609610993939021120980839831173842134605117089923025444468026164578567348718360392736482132312367435114106411271743218631041094275894508404221506482038656928803775293360599721583316194630449469869000491476753827928793659938654925187969087524783314008405767753004191090522037968098548258698350055999105058915648497702724525585509

================================================

n2 = 17730912385401458370516374144454354828481353051514329263921774569034415114147424203611660978860008058118764431105602401970281692066419254457694301039461623568501484102567802483628476717695013320444442267232019104240173401975387173805390636521671252624249730700497552226732834062715286458634274525026438931671208367178653031967364951679420066768732647183187381700016195545187024094717207787859217993871236368911145957298126589666514319408022801341248744002320245345234912423717815146532293315342644702101415345900126397475592837306256140915525455824350305349773210334856093169535686115299159772550674315375987529523179

e2 = 3

c2 = 8177192204481601898705460379101384591996531766013815643642297541939314169289538943467463950155787562006058743758523755363825964609610993939021120980839831173842134605117089923025444468026164578567348718360392736482132312367435114106411271743218631041094275894508404221506482038656928803775293360599721583316194630449469869000491476753827928793659938654925187969087524783314008405767753004191090522037968098548258698350055999105058915648497702724525585509

================================================

n3 = 23693871552180460990138635073805949225912252125308334418081834697641804631104724668330415198785050388969117484647897131795893896100932121531733121069301557203541651575306855376180158639595396645851251320756224273151350168394783274111111375428683335001923152182758469432988805562827169898721409159172411067426322303967736140645806651181720610635139163613355013365367013643617931710120446074129630384181873406149243284193113399417540744056880787819360491511062694356302764642727497777585348003477373456680752873785829149551421840290660162776229985812994060664107888011786183808824620497078292008444842754064007647832261

e3 = 3

c3 = 8177192204481601898705460379101384591996531766013815643642297541939314169289538943467463950155787562006058743758523755363825964609610993939021120980839831173842134605117089923025444468026164578567348718360392736482132312367435114106411271743218631041094275894508404221506482038656928803775293360599721583316194630449469869000491476753827928793659938654925187969087524783314008405767753004191090522037968098548258698350055999105058915648497702724525585509

e가 3이고, n이 세 개가 주어졌으므로, 브로드캐스트 공격을 시행한다.

Pasted image 20230601235301

Forensics

kcpassword

Description :
I'm too lazy to log into my Mac each time, so I enabled auto-logon. It's okay though because I'm sure that Apple will protect my password sufficiently...

Attached file : [kcpassword]

MAC에서 자동 로그인을 활성화 할 경우 etc/kcpassword 파일이 생성되며, 해당 파일은 따로 암호화 없이 xor 연산으로만 생성된다고 한다.

#!/usr/bin/python3

import struct
import sys

# Function to decrypt the kcpassword
def decrypt_kcpassword():
    key = [125, 137, 82, 35, 210, 188, 221, 234, 163, 185, 31]
    length = len(key)
    f = open(sys.argv[1], "rb")
    byte = list(f.read())
    f.close()

    end = False
    kcpassword = []
    for i in range(len(byte)):
        if byte[i]^key[i%length] == 0 :
            end = True

        if end == False :
            kcpassword.append(str(chr(byte[i]^key[i%length])))

    print(''.join(map(str,kcpassword)))

# Function main
def main():
    if len(sys.argv) < 2 :
        print('usage : ./decode-kcpassword.py KCPASSWORD_PATH')
        exit()
    decrypt_kcpassword()

# Call to main
if __name__ == '__main__':
    main()
  • 확인된 flag -> byuctf{wow_Macs_really_have_it_encrypted_with_a_static_key_lol}