Format Strings
Basiese Inligting
In C printf
is 'n funksie wat gebruik kan word om te druk 'n string. Die eerste parameter wat hierdie funksie verwag is die rou teks met die formateerders. Die volgende parameters wat verwag word is die waardes om die formateerders van die rou teks te vervang.
Ander kwesbare funksies is sprintf()
en fprintf()
.
Die kwesbaarheid verskyn wanneer 'n aanvaller teks as die eerste argument vir hierdie funksie gebruik word. Die aanvaller sal in staat wees om 'n spesiale invoer te vervaardig wat die printf formaat string vermoëns misbruik om te lees en skryf enige data in enige adres (leesbaar/skryfbaar). Op hierdie manier in staat om arbitraire kode uit te voer.
Formateerders:
Voorbeelde:
Kwetsbare voorbeeld:
Normale Gebruik:
Met ontbrekende argumente:
fprintf kwesbaar:
Toegang tot Pointers
Die formaat %<n>$x
, waar n
'n getal is, laat toe om aan printf aan te dui om die n parameter (van die stapel) te kies. So as jy die 4de parameter van die stapel met printf wil lees, kan jy doen:
en jy sou van die eerste tot die vierde parameter lees.
Of jy kan doen:
and lees direk die vierde.
Let op dat die aanvaller die printf
parameter beheer, wat basies beteken dat sy invoer in die stapel gaan wees wanneer printf
aangeroep word, wat beteken dat hy spesifieke geheue adresse in die stapel kan skryf.
'n Aanvaller wat hierdie invoer beheer, sal in staat wees om arbitraire adresse in die stapel by te voeg en printf
te laat toegang tot hulle. In die volgende afdeling sal verduidelik word hoe om hierdie gedrag te gebruik.
Arbitraire Lees
Dit is moontlik om die formatter %n$s
te gebruik om printf
die adres wat in die n posisie geleë is, te laat kry, wat volg en dit asof dit 'n string is te druk (druk totdat 'n 0x00 gevind word). So as die basisadres van die binêre 0x8048000
is, en ons weet dat die gebruiker se invoer in die 4de posisie in die stapel begin, is dit moontlik om die begin van die binêre te druk met:
Let daarop dat jy nie die adres 0x8048000 aan die begin van die invoer kan plaas nie, omdat die string in 0x00 aan die einde van daardie adres sal wees.
Vind offset
Om die offset na jou invoer te vind, kan jy 4 of 8 bytes (0x41414141
) stuur, gevolg deur %1$x
en verhoog die waarde totdat jy die A's
ontvang.
Last updated