Article View: es.comp.os.linux.programacion
Article #10845Re: Distinguir descriptor
From: Lokutus
Date: Fri, 25 Jan 2002 23:55
Date: Fri, 25 Jan 2002 23:55
84 lines
2890 bytes
2890 bytes
Ignacio Arenaza wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>>>>>> "Lokutus" == Lokutus <Lokutus2000@nclack.mar> writes:
>
> Lokutus> �Como se puede distinguir si un descriptor de ficheros
> Lokutus> es de un socket o de un fichero o de un controlador de
> Lokutus> dispositivos?
>
> man fstat(2). Echa una ojeada a las macros S_IS*
>
> Saludos. I�aki.
>
Gracias,
aunque no consigo que me funcione como quiero.
/*******************************************************
Forma de uso, renombrar /bin/bash como /bin/kkkkk
y renombrar este programa como /bin/bash
Si alguien se conecta desde la red, (cualquier m�todo),
ser� desconectado nada m�s ejecutar este falso /bin/bash
*******************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char *argv)
{
/*char sEjec[] = "/bin/kkkkk";*/
char sEjec[] = "kkkkk"; /* para depurar, un Hola Mundo */
struct stat tInfo;
/* Paso numero 1, determinar si stdin, se corresponde con un
socket o con la consola.*/
fstat(1, &tInfo);
if ((tInfo.st_mode & S_IFSOCK) != S_IFSOCK) {
/* if (S_ISSOCK(tInfo.st_mode)) {*/
/* if (isatty(0)) {*/
printf("Esta conectado al terminal [%s].\n", ttyname(0));
/* Aqui ejecutar programa. */
//&argv[0] = sEjec;
execvp(sEjec, &argv);
} else {
/* No esta conectado a un tty, es un socket
* se ha conectado por telnet, o backdoor o xploit
* cierro la conexion y salgo
*/
printf("Adios.\n"); /* Debug */
close(0);
close(1); /* con uno s�lo bastaria */
close(2);
} /* if */
return(0);
} /* main */
--
Lokutus, asimilando la red.
Technical Details
Message-ID:
<a2srck$nq6$1@diana.bcn.ttd.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!newsfeed.bcn.ttd.net!news.bcn.ttd.net!not-for-mailReferences:
<a2ptvt$pfa$1@diana.bcn.ttd.net> <877kq71hq4.fsf@eb2ebu.ampr.org>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,4cbc2d8c4bbcdec X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2002-01-25 15:56:32 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!newsfeed.bcn.ttd.net!news.bcn.ttd.net!not-for-mail From: Lokutus <Lokutus2000@nclack.mar> Newsgroups: es.comp.os.linux.programacion Subject: Re: Distinguir descriptor Date: Sat, 26 Jan 2002 00:55:42 +0100 Organization: Parque tecnológico "Nuevo Clack" - Distrito federal de Marte Lines: 86 Message-ID: <a2srck$nq6$1@diana.bcn.ttd.net> References: <a2ptvt$pfa$1@diana.bcn.ttd.net> <877kq71hq4.fsf@eb2ebu.ampr.org> Reply-To: Lokutus2000@nclack.mar NNTP-Posting-Host: 193-153-107-252.uc.nombres.ttd.es Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8Bit User-Agent: KNode/0.6.1