Главная страница


ru.linux

 
 - RU.LINUX ---------------------------------------------------------------------
 From : Vladimir Butenko                     2:5020/400     17 Mar 2001  05:11:15
 To : All
 Subject : Re: Как красивей "повесить" клиента ? ;)
 -------------------------------------------------------------------------------- 
 
 
 Stanislav Latishko <sl@sl.spb.su> wrote in message
 news:1855359375@sl.spb.su...
 
 > Wed, 14 Mar 01 16:53:27 +0300 Valentin Nechayev (VN) писАл[а] :
 
 > Да нет, он самую суть ухватил - сделать больно :)
 > Просто тут решение частное, а я интересовался общим, без привязки
 > к конкретному протоколу.
 >
 > Hу например - какая-нибудь бяка щупает порты :) Можно просто
 > отфильтровать адрес, но он может зайти с другого, и на другой ...
 > Т.е. фильтрация - это пассивная оборона, и если там вундеркинд, у
 > которого дофига свободного времени - таки найдет незаткнутую дыру:)
 > А вот поддаться ему, "пустить" засунуть нос в ... , а там его ...
 > - в другой раз предпочтет более другой об"ект для упражнений ...
 
 Пожалуйста. А то у меня тут стали какой-то "исходный код" просить
 (никто не знает, что это такое?) и вообще мне вчера жутко не хотелось
 работать, так что - вот вам. Перевести на тот язык, который знаете,
 смогете, наверное. Если багу найдете - флагу Вам в руки, я нетверезый
 писал, сами и поправите - раз уж упенсурса захотелось.
 
 Так как читалки-писалки все равно заврапают этот текст,
 то сразу говорю:
 а) строчки длинные
 б) табуляция исходно стояла на 2 (где она осталась - лень было вычищать)
 в) проще стащить отсюда - http://www.stalker.com/~butenko/FireBack.txt
 
 ------
 // GangFiresBack
 //
 // Copyright (c) 2001 Vladimir A. Butenko
 //
 // The right to use this product of my not so sober evening is
 //    granted to everybody except all government agencies,
 //    communist activists (including the open source movement activists),
 //    and serial killers.
 //
 
 program GangFiresBack is
 
   constant trapPort    : STInetPort := 133;      // or what do they usually
 like to scan and try?
   constant gangPort    : STInetPort := 23456;    // all servers in our gang
 will use this port
 
   constant noopTimer   : integer    := STSeconds(15);
 
   constant tPassCommand: string     := "PASS";
   constant tOKResponse : string     := "OK";
   constant tNoopCommand: string     := "NOOP";
   constant tFireCommand: string     := "FIRE";
 
   theLock              : STLock;
   socketTable     : array of STSocket;
 
   dispatcherListener   : STSocket      := STBadSocket;
   dispatcherLink       : STSocket      := STBadSocket;
   dispatcherAddress    : STInetAddress := STInetLoopAddress;
 
   password             : string(256);
 
 //
 // The main unit
 //   if you use some stupid Unix OS, you would have to pass parameters
 as --parameter [value]
 //   strings on a so-called "command line" (those who are born after 1970
 still cannot believe
 //   that such a thing existed back in early 1980th. They think it was
 invented with their "linux"
 //   toy, to make them feel proud of themselves).
 //
 procedure main is
   // let this prototype system use simple plain-text passwords
   //
   password := readStringOption("password");
 
   // if we are the gang dispatcher, prepare to get connections from the
 members
   //  otherwise, start the Reader thread to talk to the dispatcher
   //
   isDispatcher      : boolean       := hasOption("isDispatcher");
 
   if isDispatcher then
      dispatcherListener := STCreateListener(gangPort,STInetAnyAddress);
   if dispatcherListener = STBadSocket then
     abend("cannot open the gang listener port");
      end if;
      STDetachThread(Dispathcer,null);
   else
      dispatcherAddress := readInetAddressOption("Dispatcher");
   if dispatcherListener = STInetBadAddress then
     abend("the Dispatcher address must be specified");
   end if;
   STDetachThread(Reader,null);
   end if;
 
   //
   // now we are ready to intercept attacks - and fire back!
   //
   attackListener : STSocket := STCreateListener(trapPort,STInetAnyAddress);
   if attackListener = STBadSocket then
      abend("cannot open the attack listener port");
   end if;
 
   loop
     attackerAddress : STInetAddress;
     connection      : STSocket :=
 STAcceptConnection(listener,attackerAddress);
     if connection = STBadSocket then
       abend("accept failed on the attacker port");
     else if isDispatcher then
       NotifyGang(attackerAddress,STInetBadAddress);
    FireBack(attackerAddress);
     else
       NotifyDispatcher(attackerAddress);
       FireBack(attackerAddress);
     end if;
   end loop;
 end procedure Main;
 
 //
 // This is the main Dispatcher thread
 //  we wait for new gang connections here
 //  and create threads that will watch how the gang memebers are doing
 //
 procedure Dispatcher(dummy : in STSocket) is
   loop
     peerAddress : STInetAddress;
     connection  : STSocket := STAcceptConnection(listener,peerAddress);
     if connection = STBadSocket then
       abend("accept failed on the gang port");
     end if;
  if not STDetachThread(GangAgent,connection) then
    STCloseSocket(connection);
    warning("failed to create a thread");
  end if;
   end loop;
 end procedure Dispatcher;
 
 //
 // This is the dispatcher's gang memeber agent thread body
 //
 procedure GangAgent(theClient : in STSocket) is
   //
   // first we check the potential gang memeber credentials
   //
   begin
     request : string(password'maxSize + tPassCommand'size + 1);
     if not
 STReadStringTillCRLF(theClient,request,request'maxSize,STSeconds(15)) or
     not STCheckAndRemoveKeywordAndSpaces(request,tPassCommand) or
     request =/= password then
       warning("%i attempt to jong our gang
 failed",theClient.remoteAddress());
    STCloseSocket(theClient);
     end if;
   end;
 
   // password was correct, send OK to the new gang memeber
   STSendCommandAndStringWithCRLF(theClient,tOKResponse,null);
   // include this client (its socket) into the table
   begin
     theLock.lock();
  clientTable.add(theClient);
     theLock.unlock();
   end;
   // sit and wait for commands from that member. Only NOOP and FIRE are
 implemented
   loop
     request : string(255);
   exit when not
 STReadStringTillCRLF(theClient,request,request'maxSize,STTime'Unlimited);
  if STCheckAndRemoveKeywordAndSpaces(request,tNoopCommand) then
    null;
  else if STCheckAndRemoveKeywordAndSpaces(request,tFireCommand) then
    attackerAddress : STInetAddress = STReadInetAddress(request);
    if attackerAddress =/= STAnyInetAddress then
      NotifyGang(attackerAddress,theClient.remoteAddress());
   FireBack(attackerAddress);
    end if;
  else
    warning("%i sent us a strange command:
 %s",theClient.remoteAddress(),request);
  end if;
   end loop;
 
   // exclude this client (its socket) from the table
   begin
     theLock.lock();
     index : integer := clientTable.indexOf(theClient);
     if index >= 0 then clientTable.removeElement(index);
     theLock.unlock();
   end;
   STCloseSocket(theClient);
 end procedure GangAgent;
 //
 // This is the dispatcher's gang memeber agent thread body
 //
 procedure NotifyGang(attackerAddress : in STInetAddress; excludeAddress : in
 STInetAddress) is
   attackerString : string := STInetAddressToString(attackerAddress);
 
   // checking all gang memebers (table modifications are locked here)
 
   theLock.lock();
   for index : integer in 0..clientTable.size()-1 loop
     aClient : STSocket := clientTable[index];
 
     // check the address and send this gang member the FIRE command
  if excludeAddress = STInetBadAddress or else excludeAddress =/=
 aClient.remoteAddress() then
 
    STSendCommandAndStringWithCRLF(aClient,tFireCommand,attackerString);
  end if;
   theLock.unlock();
 
 end procedure NotifyGang;
 //
 // The non-dispatcher gang member
 //
 
 procedure ConnectToController is
   if dispatcherLink =/= STBadSocket then
     STCloseSocket(dispatcherLink);  dispatcherLink := STBadSocket;
   end if;
 
   dispatcherLink := STOpenConnection(dispatcherAddress,gangPort);
   if dispatcherLink = STBadSocket then
     warning("cannot contact the dispatcher");
   end if;
 
   response : string(100);
   STSendCommandAndStringWithCRLF(dispatcherLink,tPassCommand,password);
   if not
 STReadStringTillCRLF(dispatcherLink,response,response'maxSize,STSeconds(15))
 or
      response =/= tOKResponse then
  warning("dispatcher AUTH failed");
  STCloseSocket(dispatcherLink); dispatcherLink := STBadSocket;
   end if;
 end procedure ConnectToController;
 //
 // This is non-dispatcher gang member Reader thead
 //   we sit here waiting for a command from the dispatcher (only FIRE is
 supported),
 //   and we send the NOOP command to the dispatcher from time to time
 //
 procedure Reader(dummy : STSocket) is
   loop
     loop
       theLock.lock();
       ConnectToDispatcher;
    theLock.unlock();
  exit when dispatcherLink =/= STBadSocket;
       STSleep(STMinutes(1));
     end loop;
  loop
    timedOut : boolean := false;
    request  : string(256);
     exit when not
 STReadStringTillCRLF(theClient,request,request'maxSize,noopTimer,timedOut);
    if timedOut then
         STSendCommandAndStringWithCRLF(dispatcherLink,tNoopCommand,null);
    else if STCheckAndRemoveKeywordAndSpaces(request,tFireCommand) then
      FireBack(STReadInetAddress(request));
    else
      warning("dispatcher sent a strange command: %s",request);
    end if;
     end loop;
 
     theLock.lock();
     STCloseSocket(dispatcherLink);  dispatcherLink := STBadSocket;
     theLock.unlock();
 
  warining("dispatcher connection failed");
   end loop;
 
 end procedure Reader;
 procedure NotifyDispatcher(attackerAddress : in STInetAddress) is
   attackerString : string := STInetAddressToString(attackerAddress);
 
   theLock.lock();
   if dispatcherLink =/= STBadSocket then
     STSendCommandAndStringWithCRLF(aClient,tFireCommand,attackerString);
   end if;
   theLock.unlock();
 end procedure NotifyDispatcher;
 
 //
 // This is the most exciting part: we have the address of
 //  the attacker, and we can no fire back. For example, we can
 //  initiate a syn flood here or something else
 //
 //  Note: if the our fire back attack lasts too long, it's
 //    better to use STDetachThread(FireBack,attackerAddress) then
 //    to call this procedure directly
 //
 procedure FireBack(attackerAddress : in STInetAddress) is
   <something exciting>
 end;
 end program;
 > --
 > Stanislav Latishko
 >
 > sl@sl.spb.su  ;  2:5030/949
 
 --- ifmail v.2.15dev5
  * Origin: Gamma NNTP server Moscow Russia (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 Re: Как красивей "повесить" клиента ? ;)   Vladimir Butenko   17 Mar 2001 05:11:15 
 Re: Как красивей "повесить" клиента ? ;)   Vladimir Butenko   17 Mar 2001 12:15:27 
Архивное /ru.linux/75917501e100.html, оценка 2 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional