Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Dawid Mocek */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <sys/un.h>
- #include <fcntl.h> /* A(10) B(11) C(12) D(13) E(14) F(15) */
- #define SOH 0x01
- #define STX 0x02
- #define ETX 0x03
- #define CHUNK_SIZE 8192
- #define PATH "/tmp/phpmailer.power.local.com.sock"
- char header[] = { 0x01, 0x06, 0x00, 0x01, 0x02, 0x28, 0x00, 0x00 };
- char query[] = {
- 0x01, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- /*
- ] NULL SOH CR _ / u s r /
- */
- 0x01, 0x04, 0x00, 0x01, 0x00, 0x5d, 0x03, 0x00, 0x01, 0x0d, 0x5f, 0x2f, 0x75, 0x73, 0x72, 0x2f,
- // 0x01, 0x04, 0x00, 0x01, 0x00, 0x5d, 0x03, 0x00, 0x02, 0x0d, 0x5f, 0x2f, 0x75, 0x73, 0x72,
- /*
- b i n / p e r l SO ETX R E Q E S T
- */
- 0x62, 0x69, 0x6e, 0x2f, 0x70, 0x65, 0x72, 0x6c, 0x0e, 0x03, 0x52, 0x45, 0x51, 0x55, 0x45, 0x53,
- /*
- T _ M E T H O D G E T SI BEL S C R
- */
- 0x54, 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x47, 0x45, 0x54, 0x0f, 0x07, 0x53, 0x43, 0x52,
- /*
- I P T _ F I L E N A M E / s t a
- */
- 0x49, 0x50, 0x54, 0x5f, 0x46, 0x49, 0x4c, 0x45, 0x4e, 0x41, 0x4d, 0x45, 0x2f, 0x73, 0x74, 0x61,
- /*
- t u s VT BELL S C R I P T _ N A M E
- */
- 0x74, 0x75, 0x73, 0x0b, 0x07, 0x53, 0x43, 0x52, 0x49, 0x50, 0x54, 0x5f, 0x4e, 0x41, 0x4d, 0x45,
- /*
- / s t a t u s FF NULL Q U E R Y _ S
- */
- 0x2f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x0c, 0x00, 0x51, 0x55, 0x45, 0x52, 0x59, 0x5f, 0x53,
- /*
- T R I N G NULL NULL NULL SOH EOT NULL SOH NULL NULL NULL NULL
- */
- 0x54, 0x52, 0x49, 0x4e, 0x47, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
- /*
- SOH ENQ NULL SOH NULL NULL NULL NULL
- */
- 0x01, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
- };
- /* R- T 16 znakow */
- struct twobytes {
- uint8_t cl1;
- uint8_t cl0;
- } __attribute__ ((__packed__));
- struct fcgi_record {
- uint8_t version;
- uint8_t type;
- uint8_t req1;
- uint8_t req0;
- union {
- uint16_t cl;
- struct twobytes cl8;
- };
- uint8_t pad;
- uint8_t reserved;
- } __attribute__ ((__packed__));
- uint16_t fcgi_get_record(int fd, char *buf)
- {
- struct fcgi_record fr;
- uint16_t remains = 8;
- char *ptr = (char *) &fr;
- ssize_t len;
- while(remains) {
- len = read(fd, ptr, remains);
- printf("%s", ptr);
- if( len <= 0) return 0;
- remains -= len;
- ptr += len;
- }
- remains = ntohs(fr.cl) + fr.pad;
- ptr = buf;
- while(remains) {
- len = read(fd, ptr, remains);
- printf("%s", ptr);
- if(len <= 0) return 0;
- remains -= len;
- ptr += len;
- }
- if(fr.type != 6) return 0;
- return ntohs(fr.cl);
- }
- int main(void) {
- int s, s2, t, len, size_read=0, total_size =0, size_recv=0;
- size_t n;
- int idx, new_len, cmp;
- struct sockaddr_un remote;
- char *buf = NULL;
- char *chunk = (char*)malloc(8192);
- if((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
- perror("socket()");
- exit(1);
- }
- printf("Trying to connect...\n");
- memset(&remote, 0, sizeof(struct sockaddr_un));
- remote.sun_family = AF_UNIX;
- strncpy(remote.sun_path, PATH, sizeof(remote.sun_path)-1);
- // connection
- if(connect(s, (struct sockaddr *)&remote, sizeof(struct sockaddr_un)) == -1) {
- perror("connect()");
- exit(1);
- }
- printf("Connected\n");
- memset(chunk, 0, 8192);
- send(s, query, sizeof(query), 0);
- // uint16_t ret = fcgi_get_record(s, buf);
- // printf("%s\n", buf);
- len = read(s, chunk, 8192);
- if(len > 0) {
- cmp = memcmp(chunk, header, sizeof header);
- printf("%d\n", cmp);
- for(t = 0; t < len; t++) {
- printf("%d = %#010x (%c)\n", t, chunk[t], chunk[t]);
- }
- /* if(chunk[7] == NULL) {
- new_len = len - 8;
- buf = (char *)malloc(new_len + 1);
- memset(buf, 0, new_len + 1);
- memcpy(buf, chunk+8, new_len);
- free(chunk);
- char *c = strchr(buf, SOH);
- buf = realloc(buf, 5);
- printf("%s\n", buf);
- //new_len = c - buf - 1 - 1;
- //printf("idx = %d\n", tmp1);
- for(t = 0; t < new_len; t++) {
- printf("%d = %#010x (%c)\n", t, buf[t], buf[t]);
- // }
- }*/
- }
- /*
- printf("LEN = %d\n", len);
- for(t = 0; t < len; t++) {
- printf("%d = %#010x (%c)\n", t, chunk[t], chunk[t]);
- }*/
- close(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement