howtoe.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. <ul>
  2. <li>3APA3A 3proxy tiny proxy server HowTo
  3. <br>Under construction, very incomplete
  4. <ul>
  5. <li><A HREF="#COMPILE">Compilation</A>
  6. <ul>
  7. <li><A HREF="#MSVC">How to compile 3proxy with Visual C++</A>
  8. <li><A HREF="#INTL">How to compile 3proxy with Intel C Compiler under Windows</A>
  9. <li><A HREF="#GCCWIN">How to compile 3proxy with GCC under Windows</A>
  10. <li><A HREF="#GCCUNIX">How to compile 3proxy with GCC under Unix/Linux</A>
  11. <li><A HREF="#CCCUNIX">How to compile 3proxy with Compaq C Compiler under Unix/Linux</A>
  12. </ul>
  13. <li><A HREF="#INSTALL">Proxy server installation and removal</A>
  14. <ul>
  15. <li><A HREF="#INSTNT">How to install/remove 3proxy under Windows NT/2000/XP</A>
  16. <li><A HREF="#INST95">How to install/remove 3proxy under Windows 95/98/ME</A>
  17. <li><A HREF="#INSTUNIX">How to install/remove 3proxy under Unix/Linux</A>
  18. </ul>
  19. <li><A HREF="#SERVER">Server configuration</A>
  20. <ul>
  21. <li><A HREF="#SAMPLE">Where to find configuration example</A>
  22. <li><A HREF="#LOGGING">How to set up logging</A>
  23. <li><A HREF="#LOGFORMAT">How to setup logging format</A>
  24. <li><A HREF="#LOGANALIZERS">How to use log analizers with 3proxy</A>
  25. <li><A HREF="#LAUNCH">How to start any of proxy services (HTTP, SOCKS etc)</A>
  26. <li><A HREF="#BIND">How to bind service to specific interface and port?</A>
  27. <li><A HREF="#AUTH">How to limit service access</A>
  28. <li><A HREF="#USERS">How to create user list</A>
  29. <li><A HREF="#ACL">How to limit user access to resources</A>
  30. <li><A HREF="#REDIR">How to manage redirections</A>
  31. <li><A HREF="#ROUNDROBIN">How to balance traffic between few external channgels?</A>
  32. <li><A HREF="#CHAIN">How to manage proxy chains</A>
  33. <li><A HREF="#BANDLIM">How to limit bandwidth</A>
  34. <li><A HREF="#TRAFLIM">How to limit traffic amount</A>
  35. <li><A HREF="#NETLIST">How to build network lists</A>
  36. </ul>
  37. <li><A HREF="#CLIENT">Client configuration</A>
  38. <li><A HREF="#ADMIN">Administering and information analisys</A>
  39. <ul>
  40. <li><A HREF="#NEWVERSION">How to obtain latest 3proxy version</A>
  41. <li><A HREF="#NTSERVICE">How to control 3proxy service under Windows NT/2000/XP</A>
  42. <li><A HREF="#ERRORS">Log error codes reference</A>
  43. </ul>
  44. <li><A HREF="#QUEST">How To ask quiestion not in How To?</A>
  45. </ul>
  46. <br>
  47. <ul>
  48. <hr>
  49. <li><A NAME="COMPILE">Compilation</A>
  50. <p>
  51. <ul>
  52. <li><A NAME="MSVC">How to compile 3proxy with Visual C++</A>
  53. <p>
  54. Extract source code files from 3proxy.tgz (with WinZip or another utility).
  55. Use nmake /f Makefile.msvc command
  56. </p>
  57. <li><A NAME="INTL">How to compile 3proxy with Intel C Compiler under Windows</A>
  58. <p>
  59. See <A HREF="#MSVC">How to compile 3proxy with Visual C++</A>
  60. Use Makefile.intl instead of Makefile.msvc
  61. </p>
  62. <li><A NAME="GCCWIN">How to compile 3proxy with GCC under Windows</A></li>
  63. <p>
  64. Extract source files from 3proxy.tgz (for example with tar -xzf 3proxy.tgz command if you have tar installed)
  65. Use make -f Makefile.win command.
  66. If you want to use POSIX emulation Cygwin library (normally you shouldn't) - use make -f Makefile.unix instead.
  67. Windows specific things (like installing as service) will not be available if compiled with Cygwin emulation.
  68. </p>
  69. <li><A NAME="GCCUNIX">How to compile 3proxy with GCC under Unix/Linux</A></li>
  70. <p>
  71. Use
  72. <pre>
  73. make -f Makefile.Linux
  74. </pre>
  75. for Linux or Cygwin, Makefile.Solaris* (depending on compiler version) for Solaris
  76. and Makefile.unix for different Unix-like OS. On BSD derivered systems make
  77. sure to use GNU make, sometimes it's called gmake instead of make.
  78. <br>Compilation is tested under FreeBSD/i386, NetBSD/i386, OpenBSD/i386,
  79. RH Linux/Alpha, Debian/i386, Gentoo/i386, Gentoo/PPC, Solaris/x86 but you
  80. shouldn't have problems under different Solaris, BSD or linux compatible systems.
  81. For different systems you may be required to patch Makefile or even source codes.
  82. If you want to use ODBC support, make sure to install ODBC for unix, remove -DNOODBC
  83. option from makefile compiler options and add ODBC library to linker variable.
  84. </p>
  85. </ul>
  86. <hr>
  87. <li><A NAME="CCCUNIX">How to compile 3proxy with Compaq C Compiler under Unix/Linux</A></li>
  88. <p>
  89. See <A HREF="#GCCUNIX">How to compile 3proxy with GCC under Unix/Linux</A>, use Makefile.ccc instead of Makefile.unix.
  90. </p>
  91. </ul>
  92. <hr>
  93. <li><A NAME="INSTALL">Proxy server installation and removal</A>
  94. <p>
  95. <ul>
  96. <li><A NAME="INSTNT">How to install/remove 3proxy under Windows NT/2000/XP</A>
  97. <p>
  98. Unpack 3proxy.zip to any directory, for example
  99. c:\Program Files\3proxy. If needed, create directory for storing log files,
  100. ODBC sources, etc. Create 3proxy.cfg in the 3proxy installation directory (See <A HREF="#SERVER">Server configuration</A>).
  101. If you use 3proxy before 0.6 Add
  102. <pre>
  103. service
  104. </pre>
  105. string into 3proxy.cfg. Now, start command prompt (cmd.exe).
  106. Change directory to 3proxy installation and run 3proxy.exe --install:
  107. <pre>
  108. D:\>C:
  109. C:\>cd C:\Program Files\3proxy
  110. C:\Program Files\3proxy>3proxy.exe --install
  111. </pre>
  112. Now, you should have 3proxy service installed and running. If service is not
  113. started, remove "service" string from 3proxy.cfg, run 3proxy.exe manually
  114. and correct all errors.
  115. </p><p>
  116. To remove 3proxy run 3proxy --remove:
  117. <pre>
  118. D:\>C:
  119. C:\>cd C:\Program Files\3proxy
  120. C:\Program Files\3proxy>net stop 3proxy
  121. C:\Program Files\3proxy>3proxy.exe --remove
  122. </pre>
  123. Now you can simply remove 3proxy installation directory.
  124. </p>
  125. <li><A NAME="INST95">How to install/remove 3proxy under Windows 95/98/ME</A>
  126. <p>
  127. Unpack 3proxy.zip to any directory, for example
  128. c:\Program Files\3proxy. If needed, create directory for storing log files,
  129. ODBC sources, etc. Create 3proxy.cfg in the 3proxy installation directory (See <A HREF="#SERVER">Server configuration</A>).
  130. Remove string
  131. <pre>
  132. service
  133. </pre>
  134. from 3proxy.cfg and add
  135. <pre>
  136. daemon
  137. </pre>
  138. if you want 3proxy to run in background.
  139. Create shortcut for 3proxy.exe and place it in autostart or add
  140. to registry with regedit.exe:
  141. <br>HKLM\Software\Microsoft\Windows\CurrentVersion\Run</br>
  142. Type: String
  143. <br>3proxy = "c:\Program Files\3proxy.exe" "C:\Program Files\3proxy.cfg"<br>
  144. You must use quotes if path contains space. If neccessary, restart Windows.
  145. If service is not started, check log. Remove "daemon" command from 3proxy.cfg,
  146. start 3proxy.exe manually and correct all errors.
  147. </p>
  148. <li><A NAME="INSTUNIX">How to install/remove 3proxy under Unix/Linux</A>
  149. <p>
  150. Complie 3proxy (see <A HREF="#COMPILE">Compilation</A>). Copy
  151. executables to any appropriate location (for example /usr/local/3proxy/sbin
  152. for servers and /usr/local/3proxy/bin for utilities).
  153. Create /usr/local/etc/3proxy.cfg.
  154. (see <A HREF="#SERVER">Server configuration</A>).
  155. You can change default configuration file location by specifing configuration file
  156. in 3proxy command line.
  157. Add 3proxy to system startup scripts.
  158. </p>
  159. </ul>
  160. <hr>
  161. <li><A NAME="SERVER">Server configuration</A>
  162. <p>
  163. <ul>
  164. <li><A NAME="SAMPLE">Where to find configuration example</A>
  165. <p>
  166. Server configuration example 3proxy.cfg.sample is in any 3proxy distribution.
  167. </p>
  168. <li><A NAME="LOGGING">How to set up logging</A>
  169. <p>
  170. 3proxy can log to stdout, file, ODBC datasource and
  171. syslog (Unix/Linux/Cygwin only). For using ODBC under Unix/Linux you must
  172. compile 3proxy with Unix ODBC libraries, see <A HREF="#COMPILE">Compilation</A>.
  173. You can control logging from 3proxy.cfg for all services or you can control
  174. logging of individual service, for example
  175. /usr/local/sbin/socks -l/var/log/socks.log starts SOCKS proxy with logging to file.
  176. For universal proxy (3proxy) log file rotation and archiving is supported.
  177. Log type is defined with "log" configuration file command or with
  178. -l switch on individual service invokation. log or -l is stdout logging.
  179. <pre>
  180. log filename
  181. </pre>
  182. and
  183. <pre>
  184. -lfilename
  185. </pre>
  186. specify filename for logging
  187. <pre>
  188. log @ident
  189. </pre>
  190. and
  191. <pre>
  192. -l@ident
  193. </pre>
  194. specify ident for syslog logging. If filename within "log" command contains
  195. '%' characters, it's processes as format specificator (see "logformat"). E.g.
  196. log c:\3proxy\logs\%y%m%d.log D creates file like c:\3proxy\logs\060729.log,
  197. date is generated based on local time.
  198. <pre>
  199. log &connstring
  200. </pre>
  201. specifies ODBC connection string, connstring is in format
  202. datasource,username,password (2 last are optional of
  203. datasource does not require or already has authentication information).
  204. Also, you must specify logformat to build SQL query, to insert recod into
  205. log, see <A HREF="#LOGFORMAT">How to setup logging format</A>
  206. </p>
  207. <p>
  208. Rotation and archiving may be set up with log, rotate ¨ archiver commands
  209. <pre>
  210. log filename LOGTYPE
  211. </pre>
  212. sets rotation type. LOGTYPE may be:
  213. <ul>
  214. <li>M, monthely
  215. <li>W, weekly
  216. <li>D, daily
  217. <li>H, hourly
  218. <li>‘, minutely
  219. </ul>
  220. <pre>
  221. rotate NUMBER
  222. </pre>
  223. specifies number of files in rotation (that is how many files to keep).
  224. <pre>
  225. archiver EXT COMMAND PARAMETERS
  226. </pre>
  227. Sets external archiver. EXT is extention of archived files
  228. (for example zip, gz, Z, rar etc) COMMAND and PARAMETERS are command
  229. to execute and command line PARAMETERS. Originale file is not deleted by
  230. 3proxy, this work is left for archiver.
  231. You can pass original filename to archiver with %F macro and archive filename with %A.
  232. Examples are located in
  233. 3proxy.cfg.sample
  234. </p>
  235. <li><A NAME="LOGFORMAT">How to setup logging format</A>
  236. <p>
  237. Since 0.3 version log format may be set with "logformat" command.
  238. First symbol of log format specifies format of date and time and
  239. should be L (LOCAL) or G (GMT - Grinwitch Meridian Time). Format
  240. string may contains some macro substitutions:
  241. <ul>
  242. <li> %y - Year (2 digits)
  243. <li> %Y - Year (4 digits)
  244. <li> %m - Month (2 digits)
  245. <li> %o - mOnth (3 letter abbriviation)
  246. <li> %d - Day (2 digits)
  247. <li> %H - Hour (2 digits)
  248. <li> %M - Minute (2 digits)
  249. <li> %S - Second (2 digits)
  250. <li> %t - Timestamp (seconds since January, 1 1970 00:00:00 GMT)
  251. <li> %. - Milliseconds
  252. <li> %z - Timezone in mail format (from GMT, '+' east, '-' west HHMM), For example Moscow winter time is +0300.
  253. <li> %U - Username ('-' if unknown).
  254. <li> %N - Service name (PROXY, SOCKS, POP3P, etc)
  255. <li> %p - Service port
  256. <li> %E - Error code (see. <A HREF="#ERRORS">Log error codes reference</A>)
  257. <li> %C - client IP
  258. <li> %c - client port
  259. <li> %R - target IP
  260. <li> %r - target port
  261. <li> %e - external IP address used to establish connection
  262. <li> %Q - requested IP
  263. <li> %q - requested port
  264. <li> %I - bytes received from target
  265. <li> %O - bytes sent to target
  266. <li> %n - host name from request
  267. <li> %h - hops before target (if redirection or chaning is used).
  268. see <A HREF="#CHAIN">How to use chains and parent proxies</A>)
  269. <li> %T - service specific text (for example URL requested). %X-YT
  270. where X and Y are positive numbers, only displays fields
  271. (space delimited) X to Y of the text. An example is %1-2T.
  272. </ul>
  273. Example:
  274. <pre>
  275. logformat "L%t.%. %N.%p %E %U %C:%c %R:%r %O %I %h %T"
  276. </pre>
  277. generates something like
  278. <p><font face="courier">
  279. 1042454727.0296 SOCK4.1080 000 3APA3A 127.0.0.1:4739 195.122.226.28:4739 505 18735 1 GET http://3proxy.ru/ HTTP/1.1
  280. </font>
  281. <br>(no line breaks)
  282. </p>
  283. <p>
  284. If ODBC used, logformat should specify SQL command,
  285. to insert record into log, for example
  286. <p><font face="courier">
  287. logformat "GINSERT INTO proxystat VALUES (%t, '%c', '%U', %I)"
  288. </font>
  289. <br>(no line breaks)
  290. </p>
  291. <li><A NAME="LOGANALIZERS">How to use log analizers with 3proxy</A>
  292. <p>
  293. Just make format of 3proxy logs compatible with format supported by your
  294. favourite log analizer. Examples of compatible logformats are:
  295. <br>
  296. For Squid access.log:
  297. <p><font face="courier">
  298. &quot;- +_G%t.%. %D %C TCP_MISS/200 %I %1-1T %2-2T %U DIRECT/%R application/unknown&quot;
  299. </p>
  300. or, more compatible format without %D
  301. <pre>
  302. &quot;- +_G%t.%. 1 %C TCP_MISS/200 %I %1-1T %2-2T %U
  303. DIRECT/%R application/unknown&quot;
  304. </pre>
  305. ISA 2000 proxy WEBEXTD.LOG (fields are TAB-delimited):
  306. <pre>
  307. &quot;- + L%C %U Unknown Y %Y-%m-%d %H:%M:%S
  308. w3proxy 3PROXY - %n %R %r %D
  309. %O %I http TCP %1-1T %2-2T - -
  310. %E - - -&quot;
  311. </pre>
  312. ISA 2004 proxy WEB.w3c (fields are TAB-delimited):
  313. <pre>
  314. &quot;- + L%C %U Unknown %Y-%m-%d %H:%M:%S
  315. 3PROXY - %n %R %r %D %O
  316. %I http %1-1T %2-2T - %E -
  317. - Internal External 0x0 Allowed&quot;
  318. </pre>
  319. ISA 2000/2004 firewall FWSEXTD.log (fields are TAB-delimited):
  320. <pre>
  321. &quot;- + L%C %U unnknown:0:0.0 N %Y-%m-%d
  322. %H:%M:%S fwsrv 3PROXY - %n %R %r
  323. %D %O %I %r TCP Connect - -
  324. - %E - - - - -&quot;
  325. </pre>
  326. HTTPD standard log (Apache and others):
  327. <p><font face="courier">
  328. &quot;-&quot;&quot;+_L%C - %U [%d/%o/%Y:%H:%M:%S %z] &quot;&quot;%T&quot;&quot; %E %I&quot;
  329. </p>
  330. or more compatible without error code
  331. <p><font face="courier">
  332. &quot;-&quot;&quot;+_L%C - %U [%d/%o/%Y:%H:%M:%S %z] &quot;&quot;%T&quot;&quot; 200 %I&quot;
  333. </p>
  334. <li><A NAME="LAUNCH">How to start any of proxy services (HTTP, SOCKS etc)</A>
  335. <p>
  336. 3proxy is distributed in 2 variants: as a set of standalone modules (proxy,
  337. socks, pop3p, tcppm, udppm) and as universal proxy server. These services are
  338. absolutely independant, and if you use 3proxy you needn't any of standalone
  339. modules.
  340. <br>Standalone modules are only configurable via command line interface while
  341. 3proxy uses configuration file. Many functions, such as ODBC logging, log
  342. rotation, access control, etc are only available in 3proxy, not in standalone
  343. proxies.
  344. Standalone module may be started from command line, for example:
  345. <pre>
  346. $/sbin/socks -l/var/log/socks.log -i127.0.0.1
  347. </pre>
  348. Starts SOCKS server binded to localhost ip, port 1080 with logging to
  349. /var/log/socks.log.
  350. You can get help for any standalone service with -? command line option.
  351. </p><p>
  352. If 3proxy is used you should start all services in 3proxy.cfg file. 3proxy.cfg
  353. is executed by 3proxy as a batch file. Example of 3proxy.cfg and command syntaxys
  354. can be found in
  355. 3proxy.cfg.sample.
  356. <pre>
  357. log /var/log/3proxy.log D
  358. rotate 30
  359. internal 127.0.0.1
  360. external 192.168.1.1
  361. proxy
  362. socks -p3129
  363. pop3p
  364. </pre>
  365. Starts 3 services: HTTP PROXY, SOCKS and POP3 PROXY. Each listens localhost
  366. interface with default port (3128 for HTTP, 1080 for SOCKS and 110 for POP3P)
  367. except socks started with port 3129.
  368. All logs are in file /var/log/3proxy.log (with daily date modification and
  369. rotation). 30 last files are stored.
  370. </p>
  371. <li><A NAME="BIND">How to bind service to specific interface and port?</A>
  372. <p>
  373. -i options specifies internal interface, -p - listening port. No space are
  374. allowed. To bind 'proxy' service to port 8080 on interfaces 192.168.1.1
  375. and 192.168.2.1 use
  376. <pre>
  377. proxy -p8080 -i192.168.1.1
  378. proxy -p8080 -i192.168.2.1
  379. </pre>
  380. </p>
  381. <li><A NAME="AUTH">How to limit service access</A>
  382. <p>
  383. First, always specify internal interface to accept incoming connection with
  384. 'internal' configuration command or '-i' service command. (See
  385. <A HREF="#LAUNCH">How to start any of proxy services (HTTP, SOCKS etc)</A>). If
  386. no internal interface is specified your proxy will act as open one.
  387. <p>It's also important to specify external interface to prevent access to
  388. internal network with 'external' or -e.
  389. <p>3proxy with configuration files allows to use authentication and
  390. authorization for user's access. Authentication is possible by
  391. username/password or user's NetBIOS name. Authentication type is specified by
  392. 'auth' command.
  393. <pre>
  394. auth none
  395. </pre>
  396. Disables both authentication and authorization. You can not use ACLs.
  397. <pre>
  398. auth iponly
  399. </pre>
  400. Specifies no authentication, ACLs authorization is used.
  401. <pre>
  402. auth nbname
  403. </pre>
  404. Authentication by NetBIOS name + ACLs. NetBIOS name of 'messenger' service
  405. is obrained before ACL validation. If no name is obtained it's assumed to be
  406. empty. Messenger is started by default in Windows NT/2000/XP. For Win9x
  407. WinPopUP need to be launched. This type of authentication may be spoofed
  408. by privileged local user.
  409. <pre>
  410. auth strong
  411. </pre>
  412. Authentication by username/password. If user is not registered his
  413. access is denied regardless of ACLs.
  414. <p>
  415. Different services can have different authentication levels.
  416. <pre>
  417. auth none
  418. pop3p
  419. auth iponly
  420. proxy
  421. auth strong
  422. socks
  423. </pre>
  424. It's possible to authorize access by client IP address, IP address or requested resource,
  425. target port, time, etc after authentication.
  426. (See <A HREF="#ACL">How to limit resource access</A>).
  427. </p><p>Since 0.6 version double authentication is possible, e.g.
  428. <pre>
  429. auth iponly strong
  430. allow * * 192.168.0.0/16
  431. allow user1,user2
  432. proxy
  433. </pre>
  434. strong authentication will only be used if ACL requires username to deside if
  435. access must be granted. That is, in example, strong username authentication
  436. is not required to access 192.168.0.0/16
  437. </p><p>0.6 version introduces authentication (username) caching to increase
  438. productivity. It's recommended to use authentication caching with resource
  439. or time consuming authentication types, such as nbname or external plugins
  440. (WindowsAuthentication).
  441. Caching can be set with 'authcache' command with 2 parameters: caching type
  442. and caching time (in seconds). Caching type defines the type of cached access:
  443. 'ip' - after successful authentication all connections during caching time
  444. from same IP are assigned to the same user, username is not requested.
  445. "ip,user" - username is requested and all connections from the same IP are
  446. assigned to the same user without actual authentication. "user" - same as above,
  447. but IP is not checked. "user,password" - username and password are checked
  448. against cached ones. For authentication special authentication type 'cache'
  449. must be used.
  450. Example:
  451. <pre>
  452. authcache ip 60
  453. auth cache strong windows
  454. proxy -n
  455. </pre>
  456. </p>
  457. Please note, that caching affects security. Never use caching for access to
  458. critical resources, such as web administration.
  459. <li><A NAME="USERS">How to create user list</A>
  460. <p>
  461. Userslist is created with 'users' command.
  462. <pre>
  463. users USERDESC ...
  464. </pre>
  465. With a single command it's possible to define few users, or you
  466. can use few 'users' commands. USERDESC is user description. Description
  467. consists of three semicolon delimited parts - login, password type and
  468. <pre>
  469. users admin:CL:bigsecret test:CL:password test1:CL:password1
  470. users "test2:CR:$1$lFDGlder$pLRb4cU2D7GAT58YQvY49."
  471. users test3:NT:BD7DFBF29A93F93C63CB84790DA00E63
  472. </pre>
  473. Please note the usage of quotation sign: it's required to comment out $ sign
  474. overwise used as a file inclusion macro.
  475. Next password types are available:
  476. <ul>
  477. <li>No password type: use system authentication.
  478. <li>CL - cleartext password
  479. <li>CR - crypt password, only MD5 crypt passwords are supported
  480. <li>NT - NT-hashed (MD4) passwords in hex, as used in pwdump or SAMBA
  481. </ul>
  482. NT and crypt passwords can be used to import accounts from Windows/SAMBA or
  483. Unix. For Windows you can use pwdump family of utilities.
  484. It's convenient to store accounts apart and include account file with $ macro.
  485. Because for included files newlines are treated as a space, it's possible to
  486. use atandard passwd file format:
  487. <pre>
  488. users $/etc/.3proxypasswd
  489. </pre>
  490. or
  491. <pre>
  492. users $"c:\Program Files\3proxy\passwords"
  493. </pre>
  494. It's possible to create NT and crypt passwords with mycrypt utility included
  495. in distribution.
  496. <br>Userlist is system-wide. To manage user access to specific service use ACLs.
  497. </p>
  498. <li><A NAME="ACL">How to limit user access to resources</A>
  499. <p>
  500. Commands allow, deny and flush are used to manage ACLs:
  501. <p><font face="courier">
  502. allow &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt; &lt;weekdaylist&gt; &lt;timeperiodlist&gt;
  503. <br>deny &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;weekdaylist&gt; &lt;timeperiodlist&gt;
  504. <br>flush
  505. </font>
  506. </p>
  507. 'flush' command is used to finish with existing ACL and to start new one.
  508. It's required to have different ACLs for different services.
  509. 'allow' is used to allow connection and 'deny' to deny connection. 'allow'
  510. command can be extended by 'parent' command to manage redirections (see <A NAME="REDIR">How to manage redirections</A>)). If ACL
  511. is empty it allow everything. If ACL is not empty, first matching ACL entry
  512. is searched for user request and ACL action (allow or deny) performed. If
  513. no matching record found, connection is denied and user will be asked to
  514. re-authenticate (requested for username/password). To prevent this request
  515. add 'deny *' to the end of list.
  516. <ul>
  517. <li>&lt;userlist&gt; - comma delimited list of users
  518. <li>&lt;sourcelist&gt; - comma delimited list of source (client) networks.
  519. Networks can be defined as single IP address or in CIDR form
  520. xxx.yyy.zzz.mmm/l, where l - is the length of network mask
  521. (a number of non-zero bits). 192.168.1.0/24
  522. means network with 255.255.255.0 mask.
  523. <li>&lt;targetlist&gt; - comma delimited list of target (server) networks.
  524. In 3proxy 0.6 and above it's allowed to use hostnames with wildmasks
  525. in targetlist. Wildmask may only present in the begginning or at the
  526. end of the hostname, e.g.
  527. 192.168.0.0/16,www.example.com,*wrongsite.com,*wrongcontent*.
  528. <li>&lt;targetportlist&gt; - comma delimited list of ports. I
  529. It's possible to define port ranges with -, e.g. 80,1024-65535
  530. means port 80 and all unprivileged ports.
  531. <li>&lt;commandlist&gt; - the list of allowed actions
  532. <br> CONNECT - establish outgoing TCP connection. e.g. POP3 or SOCKSv5
  533. <br> BIND - allow incoming TCP connection (SOCKSv5)
  534. <br> UDPASSOC - create UDP association (SOCKSv5)
  535. <br> ICMPASSOC - create ICMP association (not implemented)
  536. <br> HTTP_GET - HTTP GET request (HTTP proxy)
  537. <br> HTTP_PUT - HTTP PUT request (HTTP proxy)
  538. <br> HTTP_POST - HTTP POST request (HTTP proxy)
  539. <br> HTTP_HEAD - HTTP HEAD request (HTTP proxy)
  540. <br> HTTP_CONNECT - HTTP CONNECT, aka HTTPS request (HTTP proxy)
  541. <br> HTTP_OTHER - another HTTP request (HTTP proxy)
  542. <br> HTTP - any HTTP request except HTTP_CONNECT (HTTP proxy)
  543. <br> HTTPS - alias to HTTP_CONNECT (HTTP proxy)
  544. <br> FTP_GET - FTP get request (http, ftp proxy)
  545. <br> FTP_PUT - FTP put request (ftp proxy)
  546. <br> FTP_LIST - FTP list request (http, ftp proxy)
  547. <br> FTP - any FTP request
  548. <br> ADMIN - administration interface access
  549. <p>
  550. <li>&lt;weeksdays&gt; - week days numbers or periods (0 or 7 means Sunday, 1 is Monday, 1-5 means Monday through Friday).
  551. <li>&lt;timeperiodlists&gt; - a list of time periods in HH:MM:SS-HH:MM:SS format. For example,
  552. 00:00:00-08:00:00,17:00:00-24:00:00 lists non-working hours.
  553. </ul>
  554. * in ACL means &quot;any&quot;.
  555. Usage examples could be found in 3proxy.cfg.sample.
  556. </p>
  557. <li><A NAME="REDIR">How to manage redirections</A>
  558. <p>
  559. Redirections are usefull to e.g. forward requests from specific clients
  560. to different servers or proxy server. Additionally, redirections are usefull
  561. to convert proxy interface from ont format to another, e.g. requests from
  562. SOCKS proxy can be redirected to parent HTTP proxy, or SOCKSv5 client can be
  563. redirected to SOCKSv4 proxy.
  564. <br>Because 3proxy understand "transparent" web request, it can be used as an
  565. intermediate software between HTTP proxy and NAT server for transparent HTTP
  566. forwarding, because it can convert "Web server" request issued by client to
  567. "proxy request" required by proxy server. A simplest redirection is:
  568. <pre>
  569. auth iponly
  570. allow *
  571. parent 1000 http 192.168.1.1 3128
  572. proxy
  573. </pre>
  574. All trafiic of HTTP proxy is redirected to parent proxy 192.168.1.1 port 3128.
  575. <br>If port number is '0', IP address from 'parent' is used as external address
  576. for this connection (that is like -eIP, but only for connections matching
  577. 'allow').
  578. <br>Special case of redirection are local redirections. In this case both IP is
  579. 0.0.0.0 and port is 0. It's only usseful with SOCKS service. In this case no
  580. new connection is established, but request is parsed by corresponding local
  581. service. E.g.:
  582. <pre>
  583. auth iponly
  584. allow * * * 80
  585. parent 1000 http 0.0.0.0 0
  586. allow * * * 21
  587. parent 1000 ftp 0.0.0.0 0
  588. allow * * * 110
  589. parent 1000 pop3 0.0.0.0 0
  590. socks
  591. </pre>
  592. In this case all SOCKS traffic with destination port 80 is forwarded to local
  593. 'proxy' service, destination port 21 to 'ftppr' and 110 to 'pop3pr'. There is
  594. no need to run these services expicitly. Local redirections are usefull if
  595. you want to see and control via ACLs protocol specific parameters, e.g.
  596. filenames requests thorugh FTP while clients are using SOCKS.
  597. </p>
  598. <li><A NAME="ROUNDROBIN">How to balance traffic between few external channgels?</A>
  599. <p>
  600. Proxy itself doesn't manage network level routing. The only way to control
  601. outgoing channel is to select external interface. It's possible to make
  602. external interface (what is usually selected with 'external' command or
  603. '-e' option) random by using local redirection with external port 0.
  604. <pre>
  605. auth iponly
  606. allow *
  607. parent 500 http 10.1.1.101 0
  608. parent 500 http 10.2.1.102 0
  609. </pre>
  610. Now external interface is randomly selected with 0.5 probability between
  611. 10.1.1.101 and 10.2.1.102. To work as expected, different default routes
  612. must between 2 interfaces.
  613. used
  614. <p>
  615. If both interface addresses are in same network, e.g. 10.1.1.101 and 10.1.1.102
  616. and you want to select random gateway between 10.1.1.1 and 10.1.1.2, you must
  617. control it by using routing table, in case there is no default gateway route
  618. for Windows:
  619. <pre>
  620. route add -p 10.1.1.1 10.1.1.101
  621. route add -p 10.1.1.2 10.1.1.102
  622. route add -p 0.0.0.0 mask 0.0.0.0 192.168.1.1
  623. route add -p 0.0.0.0 mask 0.0.0.0 192.168.1.2
  624. </pre>
  625. If you have no second address yet, just add it. Under Linux/Unix it's better
  626. to use source routing.
  627. </p>
  628. <li><A NAME="CHAIN">How to manage proxy chains</A>
  629. <p>
  630. parent command may also be used to build a proxy chains. In this case
  631. few 'parent' commands are used for single 'allow' rule with different
  632. weights (first argument of parent command). Chain may contain any number
  633. of proxy servers, but it should be noted that every hope significantly
  634. reduces productivity. It's possible to mix different types of proxy within
  635. single chain: HTTPS (HTTP connect), SOCKS4, SOCKS5. Weight different from
  636. 1000 is used to build random chains. if weight W is below 1000, this proxy
  637. will be used as a next chain hop with probability of W/1000. That is, if
  638. the weight is 250 probability this proxy will be used for the next hope is
  639. 25%. 'parent' records with common weight of 1000 establish a group, one of
  640. these record will be used for the hop with probability according to weight.
  641. Warning: each group must have a weight even of 1000. As follows, common
  642. weight of all 'parent' records must also be even of 1000. If common weight
  643. of 'parent' records in te chain is 3000, chain has 3 hops and must be formed
  644. of 3 groups. Example:
  645. <pre>
  646. allow *
  647. parent 500 socks5 192.168.1.1 1080
  648. parent 500 connect 192.168.10.1 3128
  649. </pre>
  650. In this case we have 1 parent proxy (1 hop) which is randomely choosen between
  651. 2 hosts: 192.168.1.1 and 192.168.10.1. 2 records form a single group.
  652. <pre>
  653. allow * * * 80
  654. parent 1000 socks5 192.168.10.1 1080
  655. parent 1000 connect 192.168.20.1 3128
  656. parent 300 socks4 192.168.30.1 1080
  657. parent 700 socks5 192.168.40.1 1080
  658. </pre>
  659. In this case we have 3 groups (3 hops in the chain). First hop is 192.168.10.1,
  660. second hop is 192.168.20.1 and 3rd one is either 192.168.30.1 with probability
  661. of 30% or 192.168.40.1 with probability of 70%.
  662. </p>
  663. <li><A NAME="BANDLIM">How to limit bandwidth</A>
  664. <p>
  665. 3proxy supports bandwidth filters. To manage filters bandlimin/bandlimout and
  666. nobandlimin/nobandlimout. 'in' means incoming and 'out' - outgoing traffic.
  667. <p><font face="courier">
  668. bandlimin &lt;bitrate&gt; &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  669. <br>nobandlimin &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  670. </font>
  671. </p>
  672. Commands are applied to all services. Imagine bandwidth filters as a series of
  673. pipes. Bitrate is a pipe's width and ACLs controls the flow thorugh this pipe.
  674. <pre>
  675. bandlimin 57600 * 192.168.10.16
  676. bandlimin 57600 * 192.168.10.17
  677. bandlimin 57600 * 192.168.10.18
  678. bandlimin 57600 * 192.168.10.19
  679. </pre>
  680. Create 4 separete pipes for 4 client with emulation of modem connection.
  681. <pre>
  682. bandlimin 57600 * 192.168.10.16/30
  683. </pre>
  684. Create single pipe for all 4 clients. That is 4 clients share modem connection.
  685. In this example:
  686. <pre>
  687. nobandlimin * * * 110
  688. bandlimin 57600 * 192.168.10.16/32
  689. </pre>
  690. mail traffic from POP3 servers bypasses the pipe and has no bandwidth
  691. limitation.
  692. </p>
  693. <li><A NAME="TRAFLIM">How to limit traffic amount</A>
  694. <p>
  695. <p><font face="courier">
  696. counter &lt;filename&gt; &lt;type&gt; &lt;reportpath&gt;
  697. <br>countin &lt;number&gt; &lt;type&gt; &lt;amount&gt; &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  698. <br>nocountin &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  699. <br>countout &lt;number&gt; &lt;type&gt; &lt;amount&gt; &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  700. <br>nocountout &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  701. </font>
  702. </p>
  703. <p>
  704. You can set traffic limit per day (D), week (W), month (M), year (Y) or
  705. absolute ('N'), as specified by 'type' argument of counterin command.
  706. Traffic information is stored in binary file specified by 'filename' argument.
  707. countersutil utility can be used to manage this file.
  708. reportpath specifies location of text reports, type parameter of 'counter'
  709. command controls how often text reports are created. amount is amount of
  710. allowed traffic in Megabytes (MB). nocountin allows you to set exclusions.
  711. </p>
  712. <li><A NAME="NETLIST">How to build network lists</A>
  713. <p>Networks or users lists are often very huge. 3proxy doesn't currently
  714. supports user groups, but ones can be created by the means of include files.
  715. You can store comma-delimited lists of networks or users in the separate
  716. file and use $ macro to insert this list into 3proxy.cfg.
  717. 3proxy comes with 'dighosts'
  718. utility. This utility helps to grab the list of the network from HTTP page.
  719. It may be usefull to e.g. obtain a regullary updated list of local networks
  720. from ISP's server. A network list can be either in form of NETWORK MASK,
  721. e.g. 192.168.1.0 255.255.255.0 or NETWORK/LENGTH, e.g. 192.168.1.0/24. You can
  722. launch dighosts from 3proxy.cfg to be executed on every 3proxy startup or
  723. configuration reload:
  724. <pre>
  725. system "dighosts http://provider/network.html local.networks"
  726. allow * * $local.networks
  727. allow *
  728. parent 1000 proxy.provider 3128 *
  729. proxy
  730. flush
  731. </pre>
  732. In this example we obtain list of local networks from provider's page to
  733. local.networks file, allow direct access to these networks and redirect all
  734. connection to external networks to provider's proxy.
  735. </p>
  736. </ul>
  737. <hr>
  738. <li><A NAME="CLIENT">Client configuration</A>
  739. <p>
  740. <hr>
  741. <li><A NAME="ADMIN">Administering and information analisys</A>
  742. <p>
  743. <ul>
  744. <li><A NAME="NEWVERSION">How to obtain latest 3proxy version</A>
  745. <p>
  746. Latest version of 3proxy may be obtained
  747. <A HREF="http://3proxy.ru/">here</A>.
  748. New version may have changes and incompatibilities with previous one in files
  749. format or commands. Please, read CHANGELOG file and another documentation
  750. before installing new version.
  751. </p>
  752. <li><A NAME="NTSERVICE">How to control 3proxy service under Windows NT/2000/XP</A>
  753. <p>
  754. If installed as system service, 3proxy understands Windows service commands
  755. for START, STOP, PAUSE and RESUME. If service is PAUSEd, no new connections
  756. are accepted while older connections are processed. Currently there is no
  757. support for dynamic configuration change, so, you have to restart service
  758. completely if you have changed any configuration.
  759. You can control 3proxy service via "Services" administration ot via "net" command:
  760. <pre>
  761. net start 3proxy
  762. net stop 3proxy
  763. net pause 3proxy
  764. net continue 3proxy
  765. </pre>
  766. </p>
  767. <li><A NAME="ERRORS">Log error codes reference</A>
  768. <p>
  769. <ul>
  770. <li>0 - Operation successfully complited (connection
  771. was closed by one of peers)
  772. <li>1-9 - AUTHENTICATION ERRORS
  773. <li>1 - Access denied by ACL (deny)
  774. <li>2 - Redirection (should not appear)
  775. <li>3 - No ACL found, denied by default
  776. <li>4 - auth=strong and no username in request
  777. <li>5 - auth=strong and no matching username in configuration
  778. <li>6 - User found, wrong password (cleartext)
  779. <li>7 - User found, wrong password (crypt)
  780. <li>8 - User found, wrong password (NT)
  781. <li>9 - Redirection data not found (should not appear)
  782. <li>10 - Traffic limit exceeded
  783. <li>11-19 - CONNECTION ERRORS
  784. <li>11 - failed to create socket()
  785. <li>12 - failed to bind()
  786. <li>13 - failed to connect()
  787. <li>14 - failed to getpeername()
  788. <li>20-29 - COMMON ERRORS
  789. <li>21 - memory allocation failed
  790. <li>30-39 - CONNECT PROXY REDIRECTION ERRORS
  791. <li>31 - failed to request HTTP CONNECT proxy
  792. <li>32 - CONNECT proxy connection timed out or wrong reply
  793. <li>33 - CONNECT proxy fails to establish connection
  794. <li>34 - CONNECT proxy timed out or closed connection
  795. <li>40-49 - SOCKS4 PROXY REDIRECTION ERRORS
  796. <li>50-69 - SOCKS5 PROXY REDIRECTION ERRORS
  797. <li>70-79 PARENT PROXY CONNECTION ERRORS (identical to 1x)
  798. <li>90-99 - established connection errors
  799. <li>90 - socket error or connection broken
  800. <li>91 - TCP/IP common failure
  801. <li>92 - connection timed out
  802. <li>93 - error on reading data from server
  803. <li>94 - error on reading data from client
  804. <li>95 - timeout from bandlimin/bandlimout limitations
  805. <li>96 - error on sending data to client
  806. <li>97 - error on sending data to server
  807. <li>98 - server data limit (should not appear)
  808. <li>99 - client data limit (should not appear)
  809. <li>100 - HOST NOT FOUND
  810. <li>200-299 - UDP portmapper specific bugs
  811. <li>300-399 - TCP portmapper specific bugs
  812. <li>400-499 - SOCKS proxy specific bugs
  813. <li>500-599 - HTTP proxy specific bugs
  814. <li>600-699 - POP3 proxy specific bugs
  815. <li>999 - NOT IMPLEMENTED
  816. </ul>
  817. </p>
  818. </ul>
  819. <hr>
  820. <li><A NAME="QUEST">How To ask quiestion not in How To?</A>
  821. <p>
  822. Ask it in <A HREF="http://3proxy.ru/board4.html">3proxy forum</A>.
  823. Don't try to ask something before reading this document.
  824. </ul>
  825. </ul>
  826. <pre>$Id: howtoe.html,v 1.41 2009/02/02 10:04:49 vlad Exp $</pre>