GithubHelp home page GithubHelp logo

solusipse / fiche Goto Github PK

View Code? Open in Web Editor NEW
1.4K 1.4K 165.0 113 KB

Command line pastebin for sharing terminal output.

Home Page: http://termbin.com

License: MIT License

C 93.66% Makefile 1.12% Python 5.23%

fiche's People

Contributors

bket avatar cgie avatar dotlambda avatar hasimir avatar hmage avatar jungle-boogie avatar larsks avatar nnnn20430 avatar ohnx avatar part1zano avatar renaudallard avatar solusipse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fiche's Issues

hack machine

[root@iZ944ruexrfZ ~]# cat READ_THIS.txt
Hi, please view: http://termbin.com/nvfk for further information in regards to your files!

I hope it does not you done,however the domain is same as your main page!

[Feature Request] Daemon health status - Ping/Pong endpoint

Hi, thanks for a great project.

I'm working on setting this up in a docker/docker-compose environment and it would be helpful to have an endpoint for healthchecks that doesn't see the call as an upload. Something like a ping endpoint that returned pong to let us know the daemon is still alive. Might also not want to log those events if possible.

Dedupe?

Seems reasonable to take a sha256 of each submission, and keep track of checksum = upload. That way multiple uploads of the same content get the same URL.

Error after make

Hi
I'm on CentOS7 (but I've tried on Ubuntu as well), right after "make" I've got this:

cc main.c fiche.c -pthread -O2 -Wall -Wextra -Wpedantic -Wstrict-overflow -fno-strict-aliasing -std=gnu11 -g -O0 -o fiche
fiche.c: In function 'save_to_file':
fiche.c:764:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
	 for (int i = 0; i < s->buffer_len; i++) {
			   ^

Any idea?

Thanks :)

Looking for a maintainer

As you can see, currently I cannot find enough time to maintain this repository. I'm looking for someone to help me with this task. Is anyone interested?

Stdout

Hello,

There is any way to make fiche more silent as a ,,daemon'' without all the output on stdout?

Not receiving url on client

Output on server:

====================================
Domain name: http://localhost/
Saving files to: /app/uploads
Fiche started listening on port 9999.
Buffer size set to: 32768.
Slug size set to: 4.
Log file: /dev/stdout
====================================
Saved to: /app/uploads/cs0j/index.txt
Tue Oct 11 08:12:18 2016
Client: 172.17.0.1 (172.17.0.1)
====================================
cs0j -- Tue Oct 11 08:12:18 2016 -- 172.17.0.1 (172.17.0.1)

Output on client:

youwe@youwe-HP-ProBook-450-G2 > ~ $  echo "test" | nc localhost 9999
youwe@youwe-HP-ProBook-450-G2 > ~ $  

It looks like fiche is either unable to write to the socket or not writing anything at all.
The server is running inside a docker container, perhaps I'm missing something in my container config?

After doing some more testing: If i run echo "test" | nc localhost 9999 from the same container, I receive the url. If I bind port 9999 of the container to my local machine and run echo "test" | nc localhost 9999 on it, I don't receive anything.

Release

Please, make a release.
It will allow to create a packages for distributives.

Compiler warnings

I compiled fiche on Ubuntu 15.04 today, and while it worked, I got these warnings:

cc -pthread -O2    fiche.c   -o fiche
fiche.c: In function ‘thread_connection’:
fiche.c:95:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
         write(connection_socket, "You are not whitelisted!\n", 26);
         ^
fiche.c:104:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
         write(connection_socket, "You are banned!\n", 17);
         ^
fiche.c:119:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
         write(connection_socket, response, strlen(response));
         ^
fiche.c:125:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
         write(connection_socket, "Use netcat.\n", 12);
         ^
fiche.c: In function ‘load_list’:
fiche.c:253:5: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
     fread(buffer, fsize, 1, fp);
     ^

Thought this might be helpful.

Binding option

Hello,

I don't know if this is still maintained, but anyway it would be cool to have a binding option, because now fiche is binding on *

Regards

Link in README to chefi

Hello everyone.
For some time now I'm considering rewriting fiche (it's not a big deal, won't take more than couple of days) to fix all issues that arose during that whole time (mainly due to lack of proper error checking). This weekend I finally had some time to play with Rust, which I found amazing. I thought that maybe fiche would profit from porting to Rust.
What are your thoughts about that, guys? Would you like to see fiche rewritten into Rust, or maybe you'd like a new C version?

fiche snap

I've started a fiche snap, it builds, and works as expected, I'm just stuck figuring out a path to get fiche to return the machine ip in the response, instead of "example.com".

https://github.com/jamesbeedy/fiche/blob/snapping/snap/snapcraft.yaml

About to look at snapping up the rust version, as there is a nice rust plugin for snapcraft.

To build the above snap, in the project root run snapcraft, then to install it locally, sudo snap install fiche_0.1_amd64.snap --devmode

Merge secure branch into master

You've had a secure branch for a while, based on a couple of previous issues/pull requests. It's no longer up to date with master and it'd be great if it could just be merged in.

seg fault message

Hello,

Segmentation fault on this config:

% fiche -d site.me:9998 -u www -o bin/code
====================================
Domain name: http://site.me:9998/
Saving files to: bin/code
Fiche started listening on port 9999.
Buffer size set to: 32768.
Slug size set to: 4.
Log file: (null)
====================================
zsh: segmentation fault (core dumped)  fiche -d site.me:9998 -u www -o bin/code

"Connection reset by peer" after 32768 bytes

Example:

~$ ncat localhost 9999 <.pine-debug1
http://localhost/f/8gau5w
Ncat: Connection reset by peer.
~$ ls -l /var/www/fiche/8gau5w/index.txt
-rw-r--r-- 1 www-data www-data 32768 nov.   4 11:57 /var/www/fiche/8gau5w/index.txt
~$ ls -l .pine-debug1
-rw------- 1 tYYGH users 115080 oct.   7 10:46 .pine-debug1

This is on Debian-stable (ARMv5 32 bits). Fiche is launched like this:

fiche -d localhost/f -o /var/www/fiche -p 9999 -s 6 -u www-data -l /var/log/fiche.log

The log file shows no errors.

[openbsd] fiche is very slow locally

It takes 5 secs to do pipe local file to fiche, it's almost equal time while using termbin.com. Any idea?

# sysctl kern.version                                                      
kern.version=OpenBSD 5.8-current (GENERIC.MP) #1253: Fri Aug 21 21:33:17 MDT 2015
    [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP

# grep GH_COMMIT /home/jirib/personal/git/openbsd-mystuff/www/fiche/Makefile 
GH_COMMIT =             a85e04d8160a30c2a6e365b59189842fc5bca670
# time cat /etc/fstab | nc localhost 9999 
http://localhost/cx2j
    0m05.02s real     0m00.00s user     0m00.00s system

And before above was executed tracing of fiche was done...

  8347/-1               1440535952.430622 EMUL  "native"
  8347/1008347 fiche    1440535956.282909 STRU  struct sockaddr { AF_INET, 127.0.0.1:33215 }
  8347/1008347 fiche    1440535956.282916 RET   accept 4
  8347/1008347 fiche    1440535956.282921 CALL  setsockopt(4,SOL_SOCKET,SO_RCVTIMEO,0x7f7fffff55c0,16)
  8347/1008347 fiche    1440535956.282929 RET   setsockopt 0
  8347/1008347 fiche    1440535956.282932 CALL  setsockopt(4,SOL_SOCKET,SO_SNDTIMEO,0x7f7fffff55c0,16)
  8347/1008347 fiche    1440535956.282937 RET   setsockopt 0
  8347/1008347 fiche    1440535956.282947 CALL  __tfork(0x7f7fffff5540,24)
  8347/1008347 fiche    1440535956.282966 STRU  struct __tfork { tcb=0x18dda4c24260, tid=0x18dd9d761b10, stack=0x18de2a2afa90 }
  8347/1008347 fiche    1440535956.282983 RET   __tfork 1026255/0xfa8cf
  8347/1026255 fiche    1440535956.282986 RET   __tfork 0
  8347/1008347 fiche    1440535956.282990 CALL  accept(3,0x7f7fffff55d0,0x7f7fffff55f4)
  8347/1026255 fiche    1440535956.282996 CALL  issetugid()
  8347/1026255 fiche    1440535956.282999 RET   issetugid 0
  8347/1026255 fiche    1440535956.283004 CALL  getpid()
  8347/1026255 fiche    1440535956.283006 RET   getpid 8347/0x209b
  8347/1026255 fiche    1440535956.283007 CALL  clock_gettime(CLOCK_MONOTONIC,0x18de2a2ae730)
  8347/1026255 fiche    1440535956.283011 STRU  struct timespec { 98792<"Jan  2 04:26:32 1970">.341332003 }
  8347/1026255 fiche    1440535956.283013 RET   clock_gettime 0
  8347/1026255 fiche    1440535956.283014 CALL  stat(0x18de12581420,0x18de2a2ae6b0)
  8347/1026255 fiche    1440535956.283017 NAMI  "/etc/resolv.conf"
  8347/1026255 fiche    1440535956.283023 STRU  struct stat { dev=1040, ino=48805, mode=-rw-r--r-- , nlink=1, uid=0<"root">, gid=0<"wheel">, rdev=195823, atime=1440535956<"Aug 25 22:52:36 2015">.266296415, mtime=1440437225<"Aug 24 19:27:05 2015">.293364724, ctime=1440437225<"Aug 24 19:27:05 2015">.293364724, size=74, blocks=4, blksize=16384, flags=0x0, gen=0x0 }
  8347/1026255 fiche    1440535956.283033 RET   stat 0
  8347/1026255 fiche    1440535956.283038 CALL  open(0x18de12581420,0x10000<O_RDONLY|O_CLOEXEC>)
  8347/1026255 fiche    1440535956.283042 NAMI  "/etc/resolv.conf"
  8347/1026255 fiche    1440535956.283045 RET   open 5
  8347/1026255 fiche    1440535956.283049 CALL  fstat(5,0x18de2a2ae550)
  8347/1026255 fiche    1440535956.283052 STRU  struct stat { dev=1040, ino=48805, mode=-rw-r--r-- , nlink=1, uid=0<"root">, gid=0<"wheel">, rdev=195823, atime=1440535956<"Aug 25 22:52:36 2015">.266296415, mtime=1440437225<"Aug 24 19:27:05 2015">.293364724, ctime=1440437225<"Aug 24 19:27:05 2015">.293364724, size=74, blocks=4, blksize=16384, flags=0x0, gen=0x0 }
  8347/1026255 fiche    1440535956.283054 RET   fstat 0
  8347/1026255 fiche    1440535956.283057 CALL  read(5,0x18ddf7576000,0x4000)
  8347/1026255 fiche    1440535956.283068 GIO   fd 5 read 74 bytes
   0000:  23 20 47 65 6e 65 72 61 74 65 64 20 62 79 20 69 77 6e 30 20 64 68 63 6c 69 65 6e 74 0a 73 65 61 72 63 68 20 61 66 74 65 72 62 6f 6f 74 63 7a 2e 77  # Generated by iwn0 dhclient.search afterbootcz.w
   0031:  6c 61 6e 0a 6e 61 6d 65 73 65 72 76 65 72 20 31 32 37 2e 30 2e 30 2e 31 0a                                                                          lan.nameserver 127.0.0.1.
  8347/1026255 fiche    1440535956.283071 RET   read 74/0x4a
  8347/1026255 fiche    1440535956.283073 CALL  read(5,0x18ddf7576000,0x4000)
  8347/1026255 fiche    1440535956.283077 RET   read 0
  8347/1026255 fiche    1440535956.283080 CALL  close(5)
  8347/1026255 fiche    1440535956.283083 RET   close 0
  8347/1026255 fiche    1440535956.283092 CALL  __sysctl(1.10<kern.hostname>,0x18de2a2ae480,0x18de2a2ae460,0,0)
  8347/1026255 fiche    1440535956.283100 RET   __sysctl 0
  8347/1026255 fiche    1440535956.283102 CALL  issetugid()
  8347/1026255 fiche    1440535956.283105 RET   issetugid 0
  8347/1026255 fiche    1440535956.283107 CALL  getpid()
  8347/1026255 fiche    1440535956.283109 RET   getpid 8347/0x209b
  8347/1026255 fiche    1440535956.283110 CALL  clock_gettime(CLOCK_MONOTONIC,0x18de2a2ae760)
  8347/1026255 fiche    1440535956.283113 STRU  struct timespec { 98792<"Jan  2 04:26:32 1970">.341435022 }
  8347/1026255 fiche    1440535956.283117 RET   clock_gettime 0
  8347/1026255 fiche    1440535956.283120 CALL  getpid()
  8347/1026255 fiche    1440535956.283122 RET   getpid 8347/0x209b
  8347/1026255 fiche    1440535956.283124 CALL  clock_gettime(CLOCK_MONOTONIC,0x18de2a2ae760)
  8347/1026255 fiche    1440535956.283127 STRU  struct timespec { 98792<"Jan  2 04:26:32 1970">.341448362 }
  8347/1026255 fiche    1440535956.283128 RET   clock_gettime 0
  8347/1026255 fiche    1440535956.283139 CALL  clock_gettime(CLOCK_MONOTONIC,0x18de2a2ad540)
  8347/1026255 fiche    1440535956.283142 STRU  struct timespec { 98792<"Jan  2 04:26:32 1970">.341464216 }
  8347/1026255 fiche    1440535956.283144 RET   clock_gettime 0
  8347/1026255 fiche    1440535956.283145 CALL  getpid()
  8347/1026255 fiche    1440535956.283147 RET   getpid 8347/0x209b
  8347/1026255 fiche    1440535956.283152 CALL  socket(AF_INET,0x2<SOCK_DGRAM>,0)
  8347/1026255 fiche    1440535956.283156 RET   socket 5
  8347/1026255 fiche    1440535956.283158 CALL  fcntl(5,F_GETFL)
  8347/1026255 fiche    1440535956.283161 RET   fcntl 2
  8347/1026255 fiche    1440535956.283162 CALL  fcntl(5,F_SETFL,0x6<O_RDWR|O_NONBLOCK>)
  8347/1026255 fiche    1440535956.283164 RET   fcntl 0
  8347/1026255 fiche    1440535956.283166 CALL  connect(5,0x18de12582e10,16)
  8347/1026255 fiche    1440535956.283169 STRU  struct sockaddr { AF_INET, 127.0.0.1:53 }
  8347/1026255 fiche    1440535956.283175 RET   connect 0
  8347/1026255 fiche    1440535956.283178 CALL  sendto(5,0x18dda4c26400,0x28,0,0,0)
  8347/1026255 fiche    1440535956.283188 GIO   fd 5 wrote 40 bytes
   0000:  8a 2c 01 00 00 01 00 00 00 00 00 00 01 31 01 30 01 30 03 31 32 37 07 69 6e 2d 61 64 64 72 04 61 72 70 61 00 00 0c 00 01                             .,...........1.0.0.127.in-addr.arpa.....
  8347/1026255 fiche    1440535956.283191 RET   sendto 40/0x28
  8347/1026255 fiche    1440535956.283195 CALL  poll(0x18de2a2af7e0,1,5000)
  8347/1026255 fiche    1440535956.283258 RET   poll 1
  8347/1026255 fiche    1440535956.283279 CALL  recvfrom(5,0x18ddf7575400,0x200,0,0,0)
  8347/1026255 fiche    1440535956.283285 GIO   fd 5 read 121 bytes
   0000:  8a 2c 85 80 00 01 00 01 00 01 00 02 01 31 01 30 01 30 03 31 32 37 07 69 6e 2d 61 64 64 72 04 61 72 70 61 00 00 0c 00 01 c0 0c 00 0c 00 01 00 01 51  .,...........1.0.0.127.in-addr.arpa.............Q
   0031:  80 00 0b 09 6c 6f 63 61 6c 68 6f 73 74 00 c0 0c 00 02 00 01 00 01 51 80 00 02 c0 34 c0 34 00 01 00 01 00 01 51 80 00 04 7f 00 00 01 c0 34 00 1c 00  ....localhost.........Q....4.4......Q........4...
   0062:  01 00 01 51 80 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01                                                                                ...Q...................
  8347/1026255 fiche    1440535956.283287 RET   recvfrom 121/0x79
  8347/1026255 fiche    1440535956.283289 CALL  close(5)
  8347/1026255 fiche    1440535956.283294 RET   close 0
  8347/1026255 fiche    1440535956.283317 CALL  recvfrom(4,0x18de2a2a79e0,0x8000,0x40<MSG_WAITALL>,0,0)
  8347/1026255 fiche    1440535961.286458 GIO   fd 4 read 313 bytes
   0000:  39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 62 20 6e 6f 6e 65 20 73 77 61 70 20 73 77 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e  932b3467fb22696c.b none swap sw.932b3467fb22696c.
   0031:  61 20 2f 20 66 66 73 20 72 77 20 31 20 31 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 68 20 2f 68 6f 6d 65 20 66 66 73 20 72 77 2c 6e 6f  a / ffs rw 1 1.932b3467fb22696c.h /home ffs rw,no
   0062:  64 65 76 2c 6e 6f 73 75 69 64 2c 6e 6f 61 74 69 6d 65 2c 73 6f 66 74 64 65 70 20 31 20 32 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 64  dev,nosuid,noatime,softdep 1 2.932b3467fb22696c.d
   0093:  20 2f 74 6d 70 20 66 66 73 20 72 77 2c 6e 6f 64 65 76 2c 6e 6f 73 75 69 64 20 31 20 32 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 66 20   /tmp ffs rw,nodev,nosuid 1 2.932b3467fb22696c.f 
   00c4:  2f 75 73 72 20 66 66 73 20 72 77 2c 6e 6f 64 65 76 20 31 20 32 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 67 20 2f 75 73 72 2f 6c 6f 63  /usr ffs rw,nodev 1 2.932b3467fb22696c.g /usr/loc
   00f5:  61 6c 20 66 66 73 20 72 77 2c 6e 6f 64 65 76 20 31 20 32 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 65 20 2f 76 61 72 20 66 66 73 20 72  al ffs rw,nodev 1 2.932b3467fb22696c.e /var ffs r
   0126:  77 2c 6e 6f 64 65 76 2c 6e 6f 73 75 69 64 20 31 20 32 0a                                                                                            w,nodev,nosuid 1 2.
  8347/1026255 fiche    1440535961.286469 RET   recvfrom 313/0x139
  8347/1026255 fiche    1440535961.286482 CALL  mkdir(0x7f7fffff57a8,0755<S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH>)
  8347/1026255 fiche    1440535961.286486 NAMI  "/var/www/fiche/"
  8347/1026255 fiche    1440535961.286503 RET   mkdir -1 errno 17 File exists
  8347/1026255 fiche    1440535961.286504 CALL  mkdir(0x18ddae15eac0,0755<S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH>)
  8347/1026255 fiche    1440535961.286507 NAMI  "/var/www/fiche/cx2j"
  8347/1026255 fiche    1440535961.289748 RET   mkdir 0
  8347/1026255 fiche    1440535961.289758 CALL  open(0x18ddaf9503e0,0x601<O_WRONLY|O_CREAT|O_TRUNC>,0666<S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH>)
  8347/1026255 fiche    1440535961.289762 NAMI  "/var/www/fiche/cx2j/index.txt"
  8347/1026255 fiche    1440535961.290255 RET   open 5
  8347/1026255 fiche    1440535961.290260 CALL  fstat(5,0x18de2a2a77b0)
  8347/1026255 fiche    1440535961.290267 STRU  struct stat { dev=1044, ino=26303, mode=-rw-r--r-- , nlink=1, uid=756<"_fiche">, gid=67<"www">, rdev=0, atime=1440535961<"Aug 25 22:52:41 2015">.286447312, mtime=1440535961<"Aug 25 22:52:41 2015">.286447312, ctime=1440535961<"Aug 25 22:52:41 2015">.286447312, size=0, blocks=0, blksize=16384, flags=0x0, gen=0x0 }
  8347/1026255 fiche    1440535961.290269 RET   fstat 0
  8347/1026255 fiche    1440535961.290273 CALL  write(5,0x18ddf7576000,0x139)
  8347/1026255 fiche    1440535961.290286 GIO   fd 5 wrote 313 bytes
   0000:  39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 62 20 6e 6f 6e 65 20 73 77 61 70 20 73 77 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e  932b3467fb22696c.b none swap sw.932b3467fb22696c.
   0031:  61 20 2f 20 66 66 73 20 72 77 20 31 20 31 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 68 20 2f 68 6f 6d 65 20 66 66 73 20 72 77 2c 6e 6f  a / ffs rw 1 1.932b3467fb22696c.h /home ffs rw,no
   0062:  64 65 76 2c 6e 6f 73 75 69 64 2c 6e 6f 61 74 69 6d 65 2c 73 6f 66 74 64 65 70 20 31 20 32 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 64  dev,nosuid,noatime,softdep 1 2.932b3467fb22696c.d
   0093:  20 2f 74 6d 70 20 66 66 73 20 72 77 2c 6e 6f 64 65 76 2c 6e 6f 73 75 69 64 20 31 20 32 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 66 20   /tmp ffs rw,nodev,nosuid 1 2.932b3467fb22696c.f 
   00c4:  2f 75 73 72 20 66 66 73 20 72 77 2c 6e 6f 64 65 76 20 31 20 32 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 67 20 2f 75 73 72 2f 6c 6f 63  /usr ffs rw,nodev 1 2.932b3467fb22696c.g /usr/loc
   00f5:  61 6c 20 66 66 73 20 72 77 2c 6e 6f 64 65 76 20 31 20 32 0a 39 33 32 62 33 34 36 37 66 62 32 32 36 39 36 63 2e 65 20 2f 76 61 72 20 66 66 73 20 72  al ffs rw,nodev 1 2.932b3467fb22696c.e /var ffs r
   0126:  77 2c 6e 6f 64 65 76 2c 6e 6f 73 75 69 64 20 31 20 32 0a                                                                                            w,nodev,nosuid 1 2.
  8347/1026255 fiche    1440535961.290289 RET   write 313/0x139
  8347/1026255 fiche    1440535961.290291 CALL  close(5)
  8347/1026255 fiche    1440535961.290296 RET   close 0
  8347/1026255 fiche    1440535961.290302 CALL  gettimeofday(0x18de2a2a78c0,0)
  8347/1026255 fiche    1440535961.290305 STRU  struct timeval { 1440535961<"Aug 25 22:52:41 2015">.290305 }
  8347/1026255 fiche    1440535961.290307 RET   gettimeofday 0
  8347/1026255 fiche    1440535961.290324 CALL  write(4,0x18de2a2a7990,0x16)
  8347/1026255 fiche    1440535961.290356 GIO   fd 4 wrote 22 bytes
   0000:  68 74 74 70 3a 2f 2f 6c 6f 63 61 6c 68 6f 73 74 2f 63 78 32 6a 0a                                                                                   http://localhost/cx2j.
  8347/1026255 fiche    1440535961.290374 RET   write 22/0x16
  8347/1026255 fiche    1440535961.290376 CALL  close(4)
  8347/1026255 fiche    1440535961.290398 RET   close 0
  8347/1026255 fiche    1440535961.290406 CALL  __threxit(0x18dd9d761b10)

Copy link to clipboard

I imagine that the user wants the link copied to clipboard in most usecases

On linux, when xclip is installed the alias can be adjusted to:
"nc termbin.com 9999 | xclip -selection c"

That way the link is copied to clipboard. I do not know how this could be done on other platforms but it might be a useful hint to include on the website.

DDoS attacks

Due to massive DDoS attacks termbin.com isn't accessible now, sorry.

Readme lists basedir switch as -b

The actual basedir switch is -o. -b is for the banlist.

On a related note, if you feed a directory to -b, the program will segfault.

No error when trying to write to unwritable folder

I've just moved fiche to my new server, and it's stopped working.

If I run echo test | netcat starbeamrainbowlabs.com 9999 against my server from my laptop, it hangs and doesn't do anything.

On the server if I run netstat -peanut | grep -i fiche then I get this:

tcp        0      0 0.0.0.0:9999            0.0.0.0:*               LISTEN      998        2126201     31326/fiche     
tcp        0      0 5.196.73.75:9999        5.198.44.45:59898       CLOSE_WAIT  998        2126202     31326/fiche

There's a socket stuck in the TCP CLOSE_WAIT state. Hrm. Let's do some more investigation. What happens if I CTRL+C the command on my laptop and try again with just netcat starbeamrainbowlabs.com 9999?

tcp        0      0 0.0.0.0:9999            0.0.0.0:*               LISTEN      998        2126201     31326/fiche     
tcp        0      0 5.196.73.75:9999        5.198.44.45:59898       CLOSE_WAIT  998        2126202     31326/fiche     
tcp        0      0 5.196.73.75:9999        5.198.44.45:59908       ESTABLISHED 998        2125786     31326/fiche

Hum. That can't be right. the old connection still hasn't been closed, according to the server. (Interestingly I also encountered #31 again too, although I suspect that's because of a timeout or something) What about the laptop then? Let's CTRL + C and try a sudo netstat -peanut | grep -i netcat on the laptop.

me@laptop$ sudo netstat -peanut | grep -i netcat
me@laptop$ sudo netstat -peanut | grep -i nc

Nothing. So the laptop thinks the connection is closed, but the server appears to have other ideas.

I'm using the following fiche command:

/srv/fiche/fiche -u fiche -d starbeamrainbowlabs.com/bin -o /srv/www/bin -B 4096 -S -b /srv/fiche/fiche-bans.txt -l /srv/fiche/fiche-access.log
  • Server uname -a: Linux starbeamrainbowlabs.com 3.14.32-xxxx-grs-ipv6-64 #7 SMP Wed Jan 27 18:05:09 CET 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Laptop uname -a: Linux Snowflake 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
  • Laptop netcat: This is nc from the netcat-openbsd package. An alternative nc is available in the netcat-traditional package. usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port]

I don't know how to retrieve my netcat version.

Thoughts?

HTTPS support without config file

When using just the command line, we can specify -d foo.com and fiche just adds http:// to the front of it. How about a new flag which says that we want to use https://?

[openbsd] problem to build on openbsd 5.7 amd64 (x86_64 arch)

I'm trying to build fiche on openbsd 5.7 amd64 (from May 18 2015):

$ make
===>  Verifying specs:  c pthread
===>  found c.79.0 pthread.19.0
===>  Checking files for fiche-20150504
`/home/jirib/cvs/openbsd-ports/distfiles/fiche-20150504.tar.gz' is up to date.
>> (SHA256) fiche-20150504.tar.gz: OK
===>  Extracting for fiche-20150504
perl -i -ne '/^CFLAGS/ or print' /home/jirib/openbsd/pobj/fiche-20150504/fiche-a85e04d8160a30c2a6e365b59189842fc5bca670/Makefile
===>  Patching for fiche-20150504
===>  Configuring for fiche-20150504
===>  Building for fiche-20150504
cc -O2 -pipe -O0 -g  -Wall   -o fiche fiche.c 
/tmp//ccnMNmCD.o(.text+0xc35): In function `create_directory':
/home/jirib/openbsd/pobj/fiche-20150504/fiche-a85e04d8160a30c2a6e365b59189842fc5bca670/fiche.c:291: warning: strcpy() is almost always misused, please use strlcpy()
/tmp//ccnMNmCD.o(.text+0xb09): In function `generate_url':
/home/jirib/openbsd/pobj/fiche-20150504/fiche-a85e04d8160a30c2a6e365b59189842fc5bca670/fiche.c:274: warning: rand_r() is not random, it is deterministic.
/tmp//ccnMNmCD.o(.text+0xc42): In function `create_directory':
/home/jirib/openbsd/pobj/fiche-20150504/fiche-a85e04d8160a30c2a6e365b59189842fc5bca670/fiche.c:292: warning: strcat() is almost always misused, please use strlcat()
/tmp//ccnMNmCD.o(.text+0x252): In function `thread_connection':
/home/jirib/openbsd/pobj/fiche-20150504/fiche-a85e04d8160a30c2a6e365b59189842fc5bca670/fiche.c:69: undefined reference to `pthread_exit'
/tmp//ccnMNmCD.o(.text+0x2c0):/home/jirib/openbsd/pobj/fiche-20150504/fiche-a85e04d8160a30c2a6e365b59189842fc5bca670/fiche.c:79: undefined reference to `pthread_exit'
/tmp//ccnMNmCD.o(.text+0x457):/home/jirib/openbsd/pobj/fiche-20150504/fiche-a85e04d8160a30c2a6e365b59189842fc5bca670/fiche.c:102: undefined reference to `pthread_exit'
/tmp//ccnMNmCD.o(.text+0x520): In function `perform_connection':
/home/jirib/openbsd/pobj/fiche-20150504/fiche-a85e04d8160a30c2a6e365b59189842fc5bca670/fiche.c:126: undefined reference to `pthread_create'
/tmp//ccnMNmCD.o(.text+0x53b):/home/jirib/openbsd/pobj/fiche-20150504/fiche-a85e04d8160a30c2a6e365b59189842fc5bca670/fiche.c:129: undefined reference to `pthread_detach'
collect2: ld returned 1 exit status
*** Error 1 in /home/jirib/openbsd/pobj/fiche-20150504/fiche-a85e04d8160a30c2a6e365b59189842fc5bca670 (<sys.mk>:85 'fiche')
*** Error 1 in . (/home/jirib/cvs/openbsd-ports/infrastructure/mk/bsd.port.mk:2764 '/home/jirib/openbsd/pobj/fiche-20150504/.build_done')
*** Error 1 in /home/jirib/git/openbsd-mystuff/www/fiche (/home/jirib/cvs/openbsd-ports/infrastructure/mk/bsd.port.mk:2485 'all')

My WIP port's Makefile is at https://github.com/jirib/openbsd-mystuff/blob/master/www/fiche/Makefile

nc alternative (pure bash) (for docs)

#!/bin/bash

exec 3<>/dev/tcp/termbin.com/9999       # create FD
[ -t 0 ] && echo -en $* >&3 || cat >&3  # send it
cat <&3                                 # get the url
exec 3<&-                               # remove FD (clean up)

Usage:

echo foo bar foo | bashscript

or

bashscript test 123

OS/X and Linux tested.

Alias example:

$ alias tb2="(exec 3<>/dev/tcp/termbin.com/9999; cat >&3; cat <&3; exec 3<&-)"
$ echo foobar | tb2

Allow uploading to l.termbin.com

Uploading to l.termbin.com should be allowed, where the returned URL is already line-numbered.

i.e.

echo foo | nc l.termbin.com 9999

Would return http://l.termbin.com/xxxx

Vulnerability report

Hey there, I'm actively interested in inspecting open source C projects for vulnerabilities and bugs. Unfortunately, fiche has some issues. I reported this privately to you three weeks ago; since then, you have opened #54 asking for a new maintainer.

Anyone looking to install fiche on a public server should beware.

Summary

  • 2 use after free bugs
  • 1 stack overflow bug
  • 1 format string truncation
  • 1 incorrect argument order for declaration/definition
  • 2 uses of uninitialized variables (benign, in this case)
  • 3 unchecked malloc calls
  • 1 unchecked fopen call
  • Various warnings

Static analysis

Diff applied to Makefile

diff --git a/Makefile b/Makefile
index b75fc63..dfc04b1 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@
 # solusipse.net
 # -----------------------------------
 
-CFLAGS+=-pthread -O2
+CFLAGS+=-pthread -O2 -Wall -Wextra -pedantic
 prefix=/usr/local
 
 all: fiche

Clang's static analysis

$ scan-build make -B
scan-build: Using '/usr/bin/clang-4.0' for static analysis
/usr/bin/../lib/clang/ccc-analyzer -pthread -O2 -Wall -Wextra -pedantic    fiche.c   -o fiche
fiche.c: In function ‘load_list’:
fiche.c:340:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (fread(buffer, fsize, 1, fp) != fsize)
                                     ^~
fiche.c: In function ‘parse_parameters’:
fiche.c:537:54: warning: ‘snprintf’ output truncated before the last format character [-Wformat-truncation=]
                 snprintf(symbols, sizeof symbols, "%s", "abcdefghijklmnopqrstuvwxyz0123456789-+_=.ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                                                      ^
fiche.c:537:17: note: ‘snprintf’ output 68 bytes into a destination of size 67
                 snprintf(symbols, sizeof symbols, "%s", "abcdefghijklmnopqrstuvwxyz0123456789-+_=.ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fiche.c:319:12: warning: Use of memory after it is freed
    return strstr(BANLIST, ip_address);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
fiche.c:325:12: warning: Use of memory after it is freed
    return strstr(WHITELIST, ip_address);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
scan-build: 2 bugs found.
scan-build: Run 'scan-view /tmp/scan-build-2017-07-12-181831-20724-1' to examine bug reports.

Cppcheck's analysis

$ cppcheck --enable=all --inconclusive fiche.c 
Checking fiche.c ...
[fiche.h:112] -> [fiche.c:370]: (style, inconclusive) Function 'set_address' argument 1 names different: declaration 'serveraddr' definition 'server_address'.
[fiche.h:114] -> [fiche.c:380]: (style, inconclusive) Function 'set_address6' argument 1 names different: declaration 'serveraddr6' definition 'server_address6'.
[fiche.h:91] -> [fiche.c:390]: (style, inconclusive) Function 'bind_to_port' argument 2 names different: declaration 'serveraddr' definition 'server_address'.
[fiche.h:93] -> [fiche.c:399]: (style, inconclusive) Function 'bind_to_port6' argument 2 names different: declaration 'serveraddr6' definition 'server_address6'.
[fiche.h:98] -> [fiche.c:450]: (warning) Function 'save_to_file' argument order different: declaration 'buffer, slug, data' definition 'slug, buffer, data'
[fiche.c:220]: (style) Obsolete function 'asctime' called. It is recommended to use 'strftime' instead.
[fiche.c:74]: (error) Uninitialized variable: server_address
[fiche.c:66]: (error) Uninitialized variable: server_address6
Checking fiche.c: BSD...
Checking fiche.c: HAVE_INET6...
(information) Cppcheck cannot find all the include files (use --check-config for details)

Dynamic analysis

Diff applied to Makefile

diff --git a/Makefile b/Makefile
index b75fc63..323f77a 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@
 # solusipse.net
 # -----------------------------------
 
-CFLAGS+=-pthread -O2
+CFLAGS+=-pthread -ggdb -Wall -Wextra -pedantic -fsanitize=address -fno-omit-frame-pointer
 prefix=/usr/local
 
 all: fiche

Clang's address sanitizer

This targets a case where the output dir (basedir) is not writeable, or doesn't exist. In that case, this loop will run indefinitely, smashing the stack with each iteration's new random byte. If you limit this loop to be within the slug's size, you'll crash on the unchecked fopen in save_to_file.

$ ./fiche -d "http://localhost/" -o "/" -p 9999 -s 4 -B 8192 
====================================
Domain name: http://http://localhost//
Saving files to: /
Fiche started listening on port 9999.
Buffer size set to: 8192.
Slug size set to: 4.
Log file: (null)
====================================
=================================================================
==31816==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7f2ef66fccec at pc 0x00000047353c bp 0x7f2ef66fcb40 sp 0x7f2ef66fc2f0
READ of size 15 at 0x7f2ef66fccec thread T1
    #0 0x47353b in printf_common(void*, char const*, __va_list_tag*) (/home/jeaye/projects/reversing/fiche/fiche+0x47353b)
    #1 0x47411b in __interceptor_vprintf (/home/jeaye/projects/reversing/fiche/fiche+0x47411b)
    #2 0x4741ee in printf (/home/jeaye/projects/reversing/fiche/fiche+0x4741ee)
    #3 0x50a620 in generate_url /home/jeaye/projects/reversing/fiche/fiche.c:431:9
    #4 0x509d5d in thread_connection /home/jeaye/projects/reversing/fiche/fiche.c:145:9
    #5 0x4dc512 in __asan::AsanThread::ThreadStart(unsigned long, __sanitizer::atomic_uintptr_t*) (/home/jeaye/projects/reversing/fiche/fiche+0x4dc512)
    #6 0x7f2ef9e3e296 in start_thread (/usr/lib/libpthread.so.0+0x7296)
    #7 0x7f2ef924a1ee in __GI___clone (/usr/lib/libc.so.6+0xed1ee)

Address 0x7f2ef66fccec is located in stack of thread T1
SUMMARY: AddressSanitizer: dynamic-stack-buffer-overflow (/home/jeaye/projects/reversing/fiche/fiche+0x47353b) in printf_common(void*, char const*, __va_list_tag*)
Shadow bytes around the buggy address:
  0x0fe65ecd7940: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe65ecd7950: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe65ecd7960: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe65ecd7970: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe65ecd7980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0fe65ecd7990: 00 00 00 00 00 00 00 00 ca ca ca ca 00[04]cb cb
  0x0fe65ecd79a0: cb cb cb cb ca ca ca ca 00 00 00 00 00 00 00 00
  0x0fe65ecd79b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe65ecd79c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe65ecd79d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe65ecd79e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
Thread T1 created by T0 here:
    #0 0x431f50 in __interceptor_pthread_create (/home/jeaye/projects/reversing/fiche/fiche+0x431f50)
    #1 0x5096d9 in perform_connection /home/jeaye/projects/reversing/fiche/fiche.c:206:9
    #2 0x508d46 in main /home/jeaye/projects/reversing/fiche/fiche.c:89:19
    #3 0x7f2ef917d439 in __libc_start_main (/usr/lib/libc.so.6+0x20439)

==31816==ABORTING

Recommendation

I highly recommend that you don't write new software (especially web services) in C and there are various areas of fiche's code which are just waiting for a subtle change to allow a buffer overflow exploit, which could result in remote code execution. You have a ticket open for porting fiche to Rust and I think that's a superb idea.

In the meantime, please consider addressing these issues, adding those warning flags to your build, and running both static and dynamic analysis as part of your continuous integration.

Update release

Hows it going? Could you please tag a 1.0, or latest release of fiche? Thanks!

pid file?

Hello,

I'd like to have fiche run as a daemon on my freebsd system and I'm reading this document:
https://www.freebsd.org/doc/en/articles/rc-scripting/article.html

I have a crude but functioning script located at /usr/local/etc/rc.d/fiche and I can start it up with onestart. The problem is stopping it with sudo service fiche stop because I don't think a pid file is created by fiche. Is a pid file actually created? I don't see anything in the typical /var/run/fiche.pid section. Meanwhile, my rc.d script must have a location to even start the script.

Error:

% sudo service fiche stop
fiche not running? (check /var/run/fiche.pid).

Thanks!

Subfolder support?

Can I run the webserver address for fiche under a subfolder like https://example.com/bin? It would make setting it up much more convenient. I would still have the main listener on example.com:9999.

"Use netcat" appears

For some reason, when I am running one specific command, instead of the URL, I see just

Use netcat.

at the terminal. I am already using netcat. What am I doing wrong?

Optional line numbering?

Hey, I love Fiche, it's so convenient!

I just wish it had optional line numbering à la GitHub. Sure I could insert via a pipe with sed, but then it messes copy/paste. I would be more convenient if it was in two separate colons. Would it be a feature that anyone else finds useful?

Please do not add '/' in the end of basedir

I started '-o /var/www/fiche -b /tmp/banlist.txt' and the I see in processes '/var/www/fiche' was changed to '/var/www/fiche/'.

This confused OpenBSD rc.d framework:

...
empty, using default + echo >-o /var/www/fiche -b /tmp/banlist.txt<
>-o /var/www/fiche -b /tmp/banlist.txt<
+ readonly daemon_class
+ unset _rcflags _rcuser _rctimeout
+ pexp=/usr/local/bin/fiche -o /var/www/fiche -b /tmp/banlist.txt
+ rcexec=su -l -c daemon -s /bin/sh www -c
+ rc_bg=YES
+ rc_reload=NO
+ rc_cmd start
doing _rc_read_runfile
doing rc_check
+ pgrep -q -xf /usr/local/bin/fiche -o /var/www/fiche -b /tmp/banlist.txt
fiche
doing rc_start
+ su -l -c daemon -s /bin/sh www -c /usr/local/bin/fiche -o /var/www/fiche -b /tmp/banlist.txt &
====================================
Domain name: http://localhost/
Saving files to: /var/www/fiche/
Fiche started listening on port 9999.
====================================
doing _rc_wait start
doing rc_check
+ pgrep -q -xf /usr/local/bin/fiche -o /var/www/fiche -b /tmp/banlist.txt
...

This is not usual stuff to be done and generally people define basedirs without trailing '/'.

Thx!

file types force downloads

Hello,

Fiche will force a download of the file instead of displaying it in the browser. Nginix can display the file just fine on its own.

% file test-text.txt
test-text.txt: ASCII text, with CRLF, CR, LF line terminators, with escape sequences, with overstriking

replication steps:

script test.txt
ls -l
date
exit
cat test.txt | nc termbin.com 9999

Error running "Sudo make install"

Hello,

I get the following error when running the above command:

install -m 0755 fiche
Makefile:12: recipe for target 'install' failed

Help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.