blog.darkstar.work - a simple url encoder/decoder

 a simple url encoder/decoder
 http://blog.darkstar.work

Labels

Wirtschaft (148) Österreich (119) Pressefreiheit (118) IT (91) code (56) Staatsschulden (37) EZB (27) Pensionssystem (15)

2012-05-17

Too heavy optimization could trigger unwanted dangerous effects

All random occasional events, that occur from time to time, 
might imply a certain discrepancy between 
the estimated / preditcted / anticipated / expected system state.
and the real system state.

"A system is optimized too heavy, when a random occasional event might produce heavy damage or trigger a partial system collapse."

"A system is optimized to death, when any little random occasional event could trigger a total systemwide collapse."

2012-05-16

Simple Html Injection Detection for MS-SQL

A very simple prototype how html injection detection can be made on Microsoft SQLServer.
Please notice, that a full content injection detection is much more complex...

If Exists(Select Top 1 object_id 
  From tempdb.sys.tables Where name = '##InjWatch'
)
  Delete From ##InjWatch
Else
  Create Table ##InjWatch(
    ctext varchar(max), tab varchar(768), col varchar(768)
  );
GO 

Set TRANSACTION ISOLATION LEVEL read uncommitted;

Declare
 CheckHtmlInjectCursor Cursor FAST_FORWARD READ_ONLY For 
  Select
    'Cast([' + c.name + '] As nvarchar(Max))' As c_cast,
    c.name As c_name, '' +
    s.name + '.[' +T.name + ']' As sT_name
  From sys.tables T
  Inner Join sys.columns c On c.object_id = T.object_id
    And c.max_length > 16
    And c.system_type_id In (
      Select system_type_id From sys.types Where name In (     
      -- TODO: check XML, 'user defined' string & binary types :(
        'varchar''nvarchar''char''nchar''text''ntext'   
      )
    ) 
  Inner Join sys.schemas s On s.schema_id = T.schema_id

Declare @c_cast varchar(1024),
        @c_name varchar(768), @sT_name varchar(768)
Open CheckHtmlInjectCursor
  Fetch Next From CheckHtmlInjectCursor 
    Into @c_cast, @c_name, @sT_name

  While
 (@@FETCH_STATUS = 0)
  Begin
    Declare @execSQL nvarchar(max
    Set @execSQL = 
    'Insert Into ##InjWatch(ctext, tab, col) ' + 
    'Select ' + @c_cast + ' As ctext, ''' + 
                @sT_name + ''' As tab, ''' +
                @c_name + ''' As col ' + 
    'From   ' + @sT_name + ' ' 
    'Where (' + @c_cast + ' Like ''%<%'' And + 
                @c_cast + Like  ''%>%'') ' + 
    '  Or   ' + @c_cast + Like  ''%script:%''+ 
    '  Or   ' + @c_cast + ' Like ''%://%''' + 
    '  Or   ' + @c_cast + ' Like ''%href%''' 
    '  Or   ' + @c_cast + ' Like ''%return%'''   

    Execute sp_executesql @execSQL; 
  
    Fetch Next From CheckHtmlInjectCursor 
      Into @c_cast, @c_name, @sT_name 
  End 

Close CheckHtmlInjectCursor 
Deallocate CheckHtmlInjectCursor 


Select Distinct * From ##InjWatch 
GO

Mysql Sample:
/* CREATE TEMPORARY TABLE Test.HtmlSQLInjection (
 Content Varchar(1024) NULL
    , TableName VARCHAR(512) NOT NULL
    , ColumnName VARCHAR(512) NOT NULL
    , SchemaName VARCHAR(512) NOT NULL
); */


USE test;
DELIMITER $$
DROP PROCEDURE IF EXISTS  cursor_proc $$
CREATE PROCEDURE cursor_proc()
BEGIN

DECLARE v_done INTEGER DEFAULT 0;
DECLARE v_s VARCHAR(512) DEFAULT '';
DECLARE v_t VARCHAR(512) DEFAULT '';
DECLARE v_c VARCHAR(512) DEFAULT '';
DECLARE v_queryString VARCHAR(1024) DEFAULT '';
DECLARE CheckHtmlInjectCursor CURSOR FOR 
 select  
  information_schema.TABLES.TABLE_SCHEMA, 
        information_schema.TABLES.TABLE_NAME,
        information_schema.COLUMNS.COLUMN_NAME
 From information_schema.TABLES CALL `test`.`cursor_proc`();
CALL `test`.`cursor_proc`();

 inner join information_schema.COLUMNS 
  on information_schema.TABLES.TABLE_NAME = information_schema.COLUMNS.TABLE_NAME
where information_schema.TABLES.TABLE_SCHEMA = information_schema.COLUMNS.TABLE_SCHEMA
 and information_schema.COLUMNS.DATA_TYPE in 
 ('char', 'varchar', 'binary', 'varbinary', 'blob', 'longblob', 'text', 'mediumtext', 'longtext')
    and information_schema.COLUMNS.CHARACTER_MAXIMUM_LENGTH > 15;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = 1;

OPEN CheckHtmlInjectCursor;

read_loop: LOOP
  FETCH CheckHtmlInjectCursor INTO v_s, v_t, v_c;
 IF v_done = 1 THEN
      LEAVE read_loop;
      CLOSE CheckHtmlInjectCursor;
 END IF;
    SELECT v_c,  v_s, v_t;
    
   'SELECT ', v_c, ' FROM ', v_s, '.', v_t, '.', v_c, ' WHERE ', v_c, ' like ''%'' '));
    SET @queryString = (
  SELECT CONCAT(
   'SELECT ', v_c, '.',  v_s, '.', v_t, ' FROM ', v_t));
 PREPARE stmt FROM @queryString;
 EXECUTE stmt;
 DEALLOCATE PREPARE stmt; 
 */

END LOOP read_loop;
/* CLOSE CheckHtmlInjectCursor; */

END $$
 
DELIMITER ;


Google Groups shows NNTP-Posting-Host public for everyone

"Google Mail" shows original SMTP-Header only to account owner,
GoogleShowYouTheOrigSMTPMessage.png

but "Google Groups" shows NNTP-Posting-Host public for everyone (anonymous):

flex - fast lexical analyzer generator sample


Who remember flex: fast lexical analyzer generator? 

I have written a short mail logfile scanner sample long time ago under gnu linux with gcc and flex. MailScanner.yy  is a win32 port using gnuwin32 flex and getoptwin:


%option noyywrap

%{
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "getopt.h"
#include <string.h> 
#define MAXLEN 1024
#define OUT (void)printf


int i, j, idx, len, mode = 0;
char tmps[MAXLEN], reverse[MAXLEN];

%}
SEGA  [2][5][0-5]
SEGB  [2][0-4][0-9]
SEGC  [1][0-9]{2}
SEGD  [1-9][0-9]{0,1}
SEG   {SEGA}|{SEGB}|{SEGC}|{SEGD}
IP    {SEG}["."]{SEG}["."]{SEG}["."]{SEG}

HOSTDOMAINSEGMENT [0-9a-zA-Z_"\-"]+["."]
TOPLEVELDOMAIN [a-zA-Z]{2,7}
HOSTNAME {HOSTDOMAINSEGMENT}+{TOPLEVELDOMAIN}
USER [0-9A-Za-z_"\-""."]+

EMAIL1 {USER}"@"{HOSTNAME}
EMAIL2 {USER}"@"{IP}

URIPROTOCOL [a-zA-Z]{2,10}"://"
URISUFFIX [^ \t\n\r"@"","">""<""("")""{""}"]
URL1   {URIPROTOCOL}{HOSTNAME}{URISUFFIX}*
URL2   {URIPROTOCOL}{IP}{URISUFFIX}*

%%
<<EOF>> {
        exit(1);
    }

{EMAIL1} |
{EMAIL2} {
    
  if (strchr(yytext, '@') != (char *)NULL) 
  {
  switch((mode % 16))
    {
      case 0: 
        strcpy(tmps, yytext); 
        break;
case 1: 
        strcpy(tmps, strchr(yytext, (int)'@'));
        break;
case 2: 
        strcpy(tmps, &strchr(yytext, (int)'@')[1]);
        break;
  case 4:
        strcpy(tmps, &strchr(yytext, (int)'@')[1]);
len = strlen(tmps); 
for (j = 0, idx = 0; ((j < len) && (j < MAXLEN-1)); j++) 
{
if (tmps[j] == '.'
{
for (i = idx; i <= j; 
reverse[(len-j) + (i-idx)] = tmps[i++]);
 idx = j + 1;
}
}
for (i = idx; i <= j; i++)
{
          reverse[(len-j) + (i-idx)] = (i < len) ? tmps[i] : '.';
} 
reverse[len + 1] = '\0';
strcpy(tmps, reverse);
break;
case 8: 
        strcpy(tmps, &strrchr(yytext, (int)'.')[1]);
        break;
default:
        strcpy(tmps, yytext);
        break;
  }
  OUT("%s\n", tmps);
  }
}

{URL1} |
{URL2} {
  if (mode < 16) 
{
  switch((mode % 16)) 
  {
  case 0:
        strcpy(tmps, yytext);
        break;
  case 1:
        strcpy(tmps, strchr(yytext, (int)'/'));
        break;
  case 2:
        strcpy(tmps, &strrchr(yytext, (int)'/')[1]);      
        break;
  case 4:
        strcpy(tmps, &strrchr(yytext, (int)'/')[1]);
        len = strlen(tmps);
        for (j = 0, idx = 0; ((j < len) && (j < MAXLEN-1)); j++)
        {
          if (tmps[j] == '.'
          {
            for (i = idx; i <= j; reverse[(len-j) + (i-idx)] = tmps[i++]);
            idx = j + 1;
          }
        }
        for (i = idx; i <= j; i++)
{ 
          reverse[(len-j) + (i-idx)] = (i < len) ? tmps[i] : '.';
        }
        reverse[len + 1] = '\0';
        strcpy(tmps, reverse);
        break;
      case 8:
        strcpy(tmps, &strrchr(yytext, (int)'.')[1]);
        break;
      default:
        strcpy(tmps, yytext);
        break;
    }
    OUT("%s\n", tmps);
  }  

^[\n;] { ; }

[\r\n]+ { ; }

. { ; }

%%
void yyerror() { exit(1); }

void usage(const char *cmd) 
{
  OUT("Usage: %s [-f file] [-a ] [ -r ] [ -u ]\n", cmd);
  OUT("\tsimple email address and uri lexer reads from stdin \n");
  OUT("\t-a,--noat   \tprints FQDN email (chars left of \'@\')\n");
  OUT("\t-u,--nouser \tprints email without username \n");
  OUT("\t-t,--top    \tprints topleveldomain with option -a|-u\n");
  OUT("\t-n,--nouris \tprints only email address and not URIs\n");
  OUT("\t-r,--reverse\treverses FQDB/IP address segments\n");
  exit(0);
}

int _tmain(int argc, TCHAR** argv)
{
  static int verbose_flag;
  int c;

  while(1)
  {
  static struct option long_options[] =
    {
      {_T("help"), ARG_NONE, 0, _T('h')},
      {_T("noat"), ARG_NONE, 0, _T('a')},
      {_T("nouser"), ARG_NONE, 0, _T('u')},
      {_T("top"), ARG_NONE, 0, _T('t')},
      {_T("nouris"), ARG_NONE, 0, _T('n')},
      {_T("reverse"),     ARG_NONE, 0, _T('r')},
      { ARG_NULL,         ARG_NULL, ARG_NULL, ARG_NULL}
    }; 

    int option_index = 0;
    c = getopt_long(argc, argv, _T("hautnr:"), long_options, &option_index);
    if (c == -1) 
      break;
    switch (c) // Handle options
    {
      case 0: // If this option set a flag, do nothing else now.   
        if (long_options[option_index].flag != 0)
  break;
        _tprintf (_T("option %s"), long_options[option_index].name);
        if (optarg)
          _tprintf (_T(" with arg %s"), optarg);
        _tprintf (_T("\n"));
        break;
      case _T('u'): mode = 1;
        break
      case _T('a'): mode = 2;  
        break
      case _T('r'): mode = 4;  
        break;
      case _T('h'): usage(argv[0]);  
        break;
      case _T('t'): mode = 8;  
        break;
      case _T('n'): mode += 16;  
        break;  
      case '?': // getopt_long already printed an error message.  
        break
      defaultabort();
    }
  }
  (void) fflush(stdout);
  yyin = stdin;
  yylex();
  exit(0);
}


Files: [MailScanner.yy] [lex.yy.c]

VPN Security or secure instant linux


Howto increase VPN security, when you only need remote desktop or remote login sessions? 

When your OS at office is Win2008, 
VPN clients on bootable write protected memory sticks/ CDs/ DVDs with a special prepared linux OS can enhance security. (You can easy clone or customize a live cd and change the certificate / password all 2 months) 
You might even prepare a live cd for android or boot a special image from sdcard, but remember, that an image on sdcard isn't write protected.
USB Memory Stick with write protection 

Urheberrecht Führerschein

Eine berechtigte Frage und ein guter Vergleich von Igor Sekowski zum Urheberrecht: https://plus.google.com/u/0/112832268641330799683/posts/9rKTXnWkApY

Ich habe folgende Infos im Netz gefunden, die sich leider (oder wie beim Urheberrecht sehr häufig) widersprechen.
Dieser Artikel wurde bereits auf Google+ öfters erwähnt:
http://rechtsanwalt-schwenke.de/vorschaubilder-beim-teilen-von-inhalten-in-social-media-praxistipps-zur-minderung-des-abmahnrisikos/

Diese Infos habe ich so gefunden: 

und folgendes Kommentar geschrieben:
Da zumindest größtenteils Einigkeit darüber herrscht, dass wenn auf einer Webseite ein +1 oder like Button vorhanden ist, diese Webseite bei Google+ oder Facebook mit Vorschaubild geteilt werden kann, 
hätte ich als reiner Benutzer folgende ganz praktische Frage:

Ist es unproblematisch die Seite auch in jenen Sozialen Medien zu teilen, wo der entsprechende Button fehlt, sofern nur ein einziger social media share button auf der Webseite vorhanden ist?


Ein Beispiel: Jemand, egal jetzt ob unwissentlich oder absichtlich fügt nur den Facebook like Button auf seiner Webseite hinzu. Auf alle Fälle dürfte es  jetzt unproblematisch sein, wenn ich mit Vorschaubild bei Facebook diese Seite teile. Aber besteht für mich als Benutzer ein höheres Abmahnrisiko, wenn ich die Seite jetzt bei Google+ teile?

Darf der Inhaber der Seite darüber bestimmen in welchen Sozial Medien seine Seite mit Vorschaubild geteilt wird und wenn ja hätte das nicht einen extremen Wettbewerbsnachteil für neue Startups von bis dato unbekannten social media?


Hier eine Diskussion zu diesem Thema auf  Google+:
https://plus.google.com/u/0/107370420028985054014/posts/AZuWDxDif3P


http://seclists.org/ 
http://seclists.org/basics/
http://seclists.org/honeypots/ 
http://seclists.org/bugtraq/
http://seclists.org/isn/

cloud-email-security


cloud email security
Coud E-Mail Dienste werden immer populärer.
Google und Microsoft stellen Email- inkl. domain & diverser anderer Services für Unternehmen und Organisationen (Preisspektrum gratis bis günstig) per Cloud zur Verfügung. 


In meinem Umfeld setzen KMUs aus ideologischen Gründen eher auf MS, während Vereine und kleine private Organisationen eher Google zugeneigt sind.
Die Serversicherheit wird (jetzt nur) im Vergleich zu halbprofessionell eingerichteten und schlecht administrierten Mailservern eher zunehmen. 

Der Verbindungsaufbau Endgerät -> Server wird für jene, die SSL seit Jahren stur ignorieren zumindest besser. 
Benutzer Endgeräte bleiben aber weiterhin auch hier die größte Sicherheitsschwachstelle.

Zum Thema E-Mail Verschlüsselung fand ich folgende android apps im market: