Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

[REŠENO] Problem sa Squid-om: ne otvara neke sajtove

[es] :: Linux mreže :: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove

Strane: 1 2

[ Pregleda: 6633 | Odgovora: 25 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

mj7
Qt/C++

Član broj: 267364
Poruke: 75
*.sc.ni.ac.rs.



+8 Profil

icon [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 20:16 - pre 139 meseci
Da objasnim. Squid server je podignut na LinuxCentOS-u. Verzija Squida je 3.1. Problem je u autentifikaciji. Username i Password korisnika je smesten u MySql bazi i skripta koja radi sa bazom i stampa "OK\n" ili "ERR\n" je pisana u Perlu i testirana.

Skripta Squid_db_auth:
Code:
#!/usr/bin/perl
# squid_db_auth.pl
# A basic squid authentication program
use strict;
use DBI;
use Getopt::Long;
use Pod::Usage;
use Digest::MD5 qw(md5 md5_hex md5_base64);
$|=1;

=pod

=head1 NAME

squid_db_auth - Database auth helper for Squid

=cut

my $dsn = "DBI:mysql:database=squid";
my $db_user = undef;
my $db_passwd = undef;
my $db_table = "passwd";
my $db_usercol = "user";
my $db_passwdcol = "password";
my $db_cond = "enabled = 1";
my $plaintext = 0;
my $md5 = 0;
my $persist = 0;
my $isjoomla = 0;
my $debug = 0;
my $hashsalt = undef;

=pod

=head1 SYNOPSIS

squid_db_auth [options]

=head1 DESCRIPTOIN

This program verifies username & password to a database

=over 8

=item    B<--dsn>

Database DSN. Default "DBI:mysql:database=squid"

=item    B<--user>

Database User

=item    B<--password>

Database password

=item    B<--table>

Database table. Default "passwd".

=item    B<--usercol>

Username column. Default "user".

=item    B<--passwdcol>

Password column. Default "password".

=item    B<--cond>

Condition, defaults to enabled=1. Specify 1 or "" for no condition
If you use --joomla flag, this condition will be changed to block=0

=item    B<--plaintext>

Database contains plain-text passwords

=item   B<--md5>

Database contains unsalted md5 passwords

=item    B<--salt>

Selects the correct salt to evaluate passwords

=item    B<--persist>

Keep a persistent database connection open between queries. 

=item  B<--joomla>

Tells helper that user database is Joomla DB.  So their unusual salt 
hashing is understood.

=back

=cut

GetOptions(
    'dsn=s' => \$dsn,
    'user=s' => \$db_user,
    'password=s' => \$db_passwd,
    'table=s' => \$db_table,
    'usercol=s' => \$db_usercol,
    'passwdcol=s' => \$db_passwdcol,
    'cond=s' => \$db_cond,
    'plaintext' => \$plaintext,
    'md5' => \$md5,
    'persist' => \$persist,
    'joomla' => \$isjoomla,
    'debug' => \$debug,
    'salt=s' => \$hashsalt,
    );

my ($_dbh, $_sth);
$db_cond = "block = 0" if $isjoomla;

sub close_db()
{
    return if !defined($_dbh);
    undef $_sth;
    $_dbh->disconnect();
    undef $_dbh;
}

sub open_db()
{
    return $_sth if defined $_sth;
    $_dbh = DBI->connect($dsn, $db_user, $db_passwd);
    if (!defined $_dbh) {
        warn ("Could not connect to $dsn\n");
    my @driver_names = DBI->available_drivers();
    my $msg = "DSN drivers apparently installed, available:\n";
    foreach my $dn (@driver_names) {
        $msg .= "\t$dn";
    }
    warn($msg."\n");
    return undef;
    }
    my $sql_query;
    $sql_query = "SELECT $db_passwdcol FROM $db_table WHERE $db_usercol = ?" . ($db_cond ne "" ? " AND $db_cond" : "");
    $_sth = $_dbh->prepare($sql_query) || die;
    return $_sth;
}

sub check_password($$)
{
    my ($password, $key) = @_;

    if ($isjoomla){
        my $salt;
        my $key2;
        ($key2,$salt) = split (/:/, $key);
        return 1 if md5_hex($password.$salt).':'.$salt eq $key;
    }
    else{
        return 1 if defined $hashsalt && crypt($password, $hashsalt) eq $key;
        return 1 if crypt($password, $key) eq $key;
        return 1 if $md5 && md5_hex($password) eq $key;
        return 1 if $plaintext && $password eq $key;
    }

    return 0;
}

sub query_db($) {
    my ($user) = @_;
    my ($sth) = open_db() || return undef;
    if (!$sth->execute($user)) {
    close_db();
    open_db() || return undef;
    $sth->execute($user) || return undef;;
    }
    return $sth;
}
my $status;

while (<>) {
    my ($user, $password) = split;
    $status = "ERR";
    $user =~ s/%(..)/pack("H*", $1)/ge;
    $password =~ s/%(..)/pack("H*", $1)/ge;

    $status = "ERR database error";
    my $sth = query_db($user) || next;
    $status = "ERR unknown login";
    my $row = $sth->fetchrow_arrayref() || next;
    $status = "ERR login failure";
    next if (!check_password($password, @$row[0]));
    $status = "OK";
} continue {
    close_db() if (!$persist);
    print $status . "\n";
}

=pod

=head1 COPYRIGHT

Copyright (C) 2007 Henrik Nordstrom <[email protected]>
Copyright (C) 2010 Luis Daniel Lucio Quiroz <[email protected]> (Joomla support)
This program is free software. You may redistribute copies of it under the
terms of the GNU General Public License version 2, or (at youropinion) any
later version.

=cut


Sto znaci da skripta radi svoj posao.

Problem se desava kada korisnik pokusava da se uloguje. Prozor za autentifikaciju se pojavi ali ne pusta dalje prilikom unosa tacnog username-a i password-a. Reaguje kao da je uneto pogresno.

Konfiguracija je prosta, sluzi za testiranje:
Code:
#
# Recommended minimum configuration:
#
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed

auth_param basic program /usr/lib/squid/squid_db_auth.pl -user someuser -password xxxx -plaintext -persist 
auth_param basic casesensitive off
auth_param basic children 8
auth_param basic credentialsttl 1 hour

acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
acl aaaa proxy_auth REQUIRED

#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
acl db-auth proxy_auth REQUIRED
http_access allow db-auth
http_access allow localhost
http_access deny all

# Deny requests to certain unsafe ports

# Deny CONNECT to other than secure SSL ports

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed

# And finally deny all other access to this proxy

# Squid normally listens to port 3128
http_port 8080

# We recommend you to use at least the following line.
hierarchy_stoplist cgi-bin ?

# Uncomment and adjust the following to add a disk cache directory.

# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid

# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern -i (/cgi-bin/|\?) 0    0%    0
refresh_pattern .        0    20%    4320


Da li se neko sretao sa ovakvim problemom?
 
Odgovor na temu

Miroslav Strugarevic

Član broj: 5038
Poruke: 2689



+68 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 20:58 - pre 139 meseci
ls -l /usr/lib/squid/squid_db_auth.pl
ps -ef | grep squid


p.s. Da li si zamenio parametre: auth_param basic program /usr/lib/squid/squid_db_auth.pl -user someuser -password xxxx -plaintext -persist
ili nisi sa mysql korisnikom?
 
Odgovor na temu

mj7
Qt/C++

Član broj: 267364
Poruke: 75
*.sc.ni.ac.rs.



+8 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 21:08 - pre 139 meseci
Naravno. Konekcija sa bazom nije problem. Vidi se sa slike http://prntscr.com/i9ar9 da skripta cita iz baze i stampa "OK\n". To bi za squid trebalo da bude dovoljno.
 
Odgovor na temu

Miroslav Strugarevic

Član broj: 5038
Poruke: 2689



+68 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 21:10 - pre 139 meseci
A moze li output one dve komande?
 
Odgovor na temu

mj7
Qt/C++

Član broj: 267364
Poruke: 75
*.sc.ni.ac.rs.



+8 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 21:14 - pre 139 meseci
Izvinjavam se, evo:

Code:
[root@server3-p4 /]# ls -l /usr/lib/squid/squid_db_auth.pl
-rwxr-xr-x. 1 root root 4201 Oct 26 15:25 /usr/lib/squid/squid_db_auth.pl
[root@server3-p4 /]# ps -ef | grep squid
root      3842     1  0 16:30 ?        00:00:00 squid -f /etc/squid/squid.conf
squid     3845  3842  0 16:30 ?        00:00:00 (squid) -f /etc/squid/squid.conf
squid     3854  3845  0 16:30 ?        00:00:00 (unlinkd)
squid     3878  3845  0 16:33 ?        00:00:00 /usr/bin/perl /usr/lib/squid/squid_db_auth.pl -user someuser -password xxxx -plaintext -persist
squid     3879  3845  0 16:33 ?        00:00:00 /usr/bin/perl /usr/lib/squid/squid_db_auth.pl -user someuser -password xxxx -plaintext -persist
squid     3880  3845  0 16:33 ?        00:00:00 /usr/bin/perl /usr/lib/squid/squid_db_auth.pl -user someuser -password xxxx -plaintext -persist
squid     3881  3845  0 16:33 ?        00:00:00 /usr/bin/perl /usr/lib/squid/squid_db_auth.pl -user someuser -password xxxx -plaintext -persist
squid     3882  3845  0 16:33 ?        00:00:00 /usr/bin/perl /usr/lib/squid/squid_db_auth.pl -user someuser -password xxxx -plaintext -persist
squid     3883  3845  0 16:33 ?        00:00:00 /usr/bin/perl /usr/lib/squid/squid_db_auth.pl -user someuser -password xxxx -plaintext -persist
squid     3884  3845  0 16:33 ?        00:00:00 /usr/bin/perl /usr/lib/squid/squid_db_auth.pl -user someuser -password xxxx -plaintext -persist
squid     3885  3845  0 16:33 ?        00:00:00 /usr/bin/perl /usr/lib/squid/squid_db_auth.pl -user someuser -password xxxx -plaintext -persist
root      4144  2345  0 16:42 pts/0    00:00:00 grep squid

 
Odgovor na temu

Miroslav Strugarevic

Član broj: 5038
Poruke: 2689



+68 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 21:16 - pre 139 meseci
Jel ti ukljucen selinux?
 
Odgovor na temu

mj7
Qt/C++

Član broj: 267364
Poruke: 75
*.sc.ni.ac.rs.



+8 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 21:18 - pre 139 meseci
Jeste:

Code:
[root@server3-p4 /]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted
 
Odgovor na temu

Miroslav Strugarevic

Član broj: 5038
Poruke: 2689



+68 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 21:20 - pre 139 meseci
Ili gasi ili /var/log/messages pa na posao :)

p.s. Probaj

setenforce 0


Pa onda da vidimo da li ce da radi.
 
Odgovor na temu

mj7
Qt/C++

Član broj: 267364
Poruke: 75
*.sc.ni.ac.rs.



+8 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 21:26 - pre 139 meseci
Radi, hvala najlepse. :)

Mozes li da mi objasnis u cemu je bio problem?
 
Odgovor na temu

Miroslav Strugarevic

Član broj: 5038
Poruke: 2689



+68 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 21:31 - pre 139 meseci
SELinux je blokirao squid. E sad sta je tacno bio problem da li je bio port na kome squid slusa ili sama perl skripta to ne znam. To mozes videti u /var/log/messages fajlu.

p.s. Ako ti SELinux ne treba tj. ako ne znas da ga podesis onda ces morati da ga izgasis pomocu ove komande:

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

Kako bi nakon eventualnog restarta servera SELinux bio izgasen.

setenforce 0 je samo privremeno resenje dok se sistem ne restartuje.
 
Odgovor na temu

maksvel

Moderator
Član broj: 107376
Poruke: 2417

Jabber: maksvel
Sajt: maksvel.in.rs


+161 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 21:37 - pre 139 meseci
..ili samo edituj /etc/sysconfig/selinux stavi selinux=permissive (beleži, ne blokira), odnosno disabled (nit' beleži, nit' blokira)

BTW, svaki put se kanim da proučim malo bolje selinux - i neku knjigu sam našao i sve, ali me strašno zamrzi, a žurba da se namesti sve da radi, pa isključim
 
Odgovor na temu

mj7
Qt/C++

Član broj: 267364
Poruke: 75
*.sc.ni.ac.rs.



+8 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove26.10.2012. u 22:00 - pre 139 meseci
Ne radim dugo u Linuxu pa su mi neke stvari nepoznate. U svakom slucaju hvala na odgovorima. :)

Jos jedno pitanje, koje su moguce posledice gasenja selinux-a?


[Ovu poruku je menjao mj7 dana 27.10.2012. u 10:42 GMT+1]
 
Odgovor na temu

Silencer
Mitrović Stevan
Smederevo

Član broj: 399
Poruke: 480
*.dynamic.isp.telekom.rs.

ICQ: 76958890


+72 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove27.10.2012. u 07:20 - pre 139 meseci
Ma SELinux ja gledam nesto kao Firewall u Windowsu (ne govorim da je on firewall vec security policy za servise) koji ugasim jer je totalno nepotrebna stvar.
Umesto da pojednostavni i da osigura sistem, on ga jos vise iskomplikuje.

Kad god sam instalirao bilo koji Linux, SELinux sam po defaultu gasio da se ne bi smarao sa njim...

Neko ce reci da je korisna stvar, dok meni npr ne treba xD sem ako nisi frik ili radis u United States National Security Agency (koji je inace i developovo ovo, pa je sad po defaultu u kernelu), onda ceti ovo trebati za Dodatni Security u Linuxu :)
 
Odgovor na temu

maksvel

Moderator
Član broj: 107376
Poruke: 2417

Jabber: maksvel
Sajt: maksvel.in.rs


+161 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove27.10.2012. u 11:02 - pre 139 meseci
Citat:
Jos jedno pitanje, koje su moguce posledice gasenja selinux-a?

Npr. - sve će raditi bez problema
Nije to ništa strašno - ko hoće baš zategnut security, SElinux je samo jedan sloj zaštite, pre toga treba staviti i npr. mod_security, pa fail2ban, eventualno tripwire i još lom drugih stvari, koje mogu biti od mnogo veće važnosti za sigurnost servera.

Teme na ES:
http://www.elitesecurity.org/t411972-0

http://www.elitesecurity.org/t167788-0
 
Odgovor na temu

mj7
Qt/C++

Član broj: 267364
Poruke: 75
*.sc.ni.ac.rs.



+8 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove27.10.2012. u 12:49 - pre 139 meseci
Jos jednom hvala na pomoci, i drago mi je sto kad se tice Linuxa uvek ima pravih ljudi koji hoce da pomognu.

Javio mi se jos jedan problem u medjuvremenu. Kad se izlazi preko proxy servera na internet desava se da npr. sajt www.vukajlija.com ucitava extra, dok www.elitesecurity.org ili www.google.com nece da ucita, prodje samo po nekad. Kad pogledam access.log ima dosta TCP_MISS/200 (he requested object was not in the cache). To ne bi trebao da bude razlog za spor internet. Firewall je podesen da radi samo log. Gde bi mogao da bude problem, koji log jos da pogledam?
 
Odgovor na temu

Miroslav Strugarevic

Član broj: 5038
Poruke: 2689



+68 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove28.10.2012. u 01:00 - pre 138 meseci
ls -ld /var/spool/squid*
 
Odgovor na temu

mj7
Qt/C++

Član broj: 267364
Poruke: 75
*.sc.ni.ac.rs.



+8 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove31.10.2012. u 17:02 - pre 138 meseci
Code:
[root@server3-p4 ~]# ls -ld /var/spool/squid*
drwxrwx---. 18 squid squid 4096 Oct 27 14:53 /var/spool/squid
 
Odgovor na temu

Miroslav Strugarevic

Član broj: 5038
Poruke: 2689



+68 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove31.10.2012. u 17:04 - pre 138 meseci
ls -lh /var/spool/squid/
 
Odgovor na temu

mj7
Qt/C++

Član broj: 267364
Poruke: 75
*.sc.ni.ac.rs.



+8 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove31.10.2012. u 17:07 - pre 138 meseci
Code:


[root@server3-p4 ~]# ls -lh /var/spool/squid/
total 76K
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 00
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 01
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 02
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 03
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 04
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 05
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 06
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 07
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 08
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 09
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 0A
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 0B
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 0C
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 0D
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 0E
drwxrwx---. 258 squid squid 4.0K Oct 24 08:31 0F
-rwxrwx---    1 squid squid 9.9K Oct 27 14:53 swap.state
 
Odgovor na temu

Miroslav Strugarevic

Član broj: 5038
Poruke: 2689



+68 Profil

icon Re: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove31.10.2012. u 17:08 - pre 138 meseci
Ajde ovako. Reci koje sve probleme imas?
 
Odgovor na temu

[es] :: Linux mreže :: [REŠENO] Problem sa Squid-om: ne otvara neke sajtove

Strane: 1 2

[ Pregleda: 6633 | Odgovora: 25 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.