-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxssi.c
141 lines (115 loc) · 3.62 KB
/
xssi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "xssi.h"
char *XSSIExec(char *RetStr, const char *TagType, const char *TagData)
{
char *Name=NULL, *Value=NULL, *Tempstr=NULL;
const char *ptr;
STREAM *S;
ptr=GetNameValuePair(TagData, "\\S", "=", &Name, &Value);
while (ptr)
{
if (strcmp(Name, "cmd")==0)
{
Tempstr=MCopyStr(Tempstr, "cmd:",Value,NULL);
S=STREAMOpen(Tempstr, "r");
if (S)
{
Tempstr=STREAMReadDocument(Tempstr, S);
RetStr=CatStr(RetStr, Tempstr);
STREAMClose(S);
}
}
if (strcmp(Name, "cgi")==0)
{
S=STREAMOpen(Value, "r");
Tempstr=STREAMReadDocument(Tempstr, S);
STREAMClose(S);
RetStr=CatStr(RetStr, Tempstr);
}
ptr=GetNameValuePair(ptr, "\\S", "=", &Name, &Value);
}
Destroy(Name);
Destroy(Value);
Destroy(Tempstr);
return(RetStr);
}
char *XSSIInclude(char *RetStr, const char *TagType, const char *TagData)
{
char *Name=NULL, *Value=NULL, *Tempstr=NULL;
const char *ptr;
STREAM *S;
ptr=GetNameValuePair(TagData, "\\S", "=", &Name, &Value);
while (ptr)
{
//when chrooted file and virtual are the same, as the root directory is also the document root
if (strcmp(Name, "file")==0)
{
S=STREAMOpen(Value, "r");
if (S)
{
Tempstr=STREAMReadDocument(Tempstr, S);
STREAMClose(S);
RetStr=CatStr(RetStr, Tempstr);
LogToFile(Settings.LogPath,"XSSI: [%s] ", RetStr);
}
}
if (strcmp(Name, "virtual")==0)
{
S=STREAMOpen(Value, "r");
if (S)
{
Tempstr=STREAMReadDocument(Tempstr, S);
STREAMClose(S);
RetStr=CatStr(RetStr, Tempstr);
}
}
ptr=GetNameValuePair(ptr, "\\S", "=", &Name, &Value);
}
Destroy(Name);
Destroy(Value);
Destroy(Tempstr);
return(RetStr);
}
char *XSSIEcho(char *RetStr, const char *TagType, const char *TagData)
{
char *Name=NULL, *Value=NULL, *Tempstr=NULL;
const char *ptr;
ptr=GetNameValuePair(TagData, "\\S", "=", &Name, &Value);
while (ptr)
{
if (strcmp(Name, "var")==0)
{
Tempstr=getenv(Value);
RetStr=CatStr(RetStr, Tempstr);
}
ptr=GetNameValuePair(ptr, "\\S", "=", &Name, &Value);
}
Destroy(Name);
Destroy(Value);
Destroy(Tempstr);
return(RetStr);
}
char *XSSITag(char *RetStr, const char *TagType, const char *TagData)
{
if (strcmp(TagType,"#include")==0) RetStr=XSSIInclude(RetStr, TagType, TagData);
else if (strcmp(TagType,"#exec")==0) RetStr=XSSIExec(RetStr, TagType, TagData);
else if (strcmp(TagType,"#echo")==0) RetStr=XSSIEcho(RetStr, TagType, TagData);
return(RetStr);
}
char *XSSIDocument(char *RetStr, const char *Document)
{
char *TagType=NULL, *Namespace=NULL, *TagData=NULL;
const char *ptr;
ptr=XMLGetTag(Document, &Namespace, &TagType, &TagData);
while (ptr)
{
if (strncmp(TagType, "!--",3)==0) RetStr=XSSITag(RetStr, TagType+3, TagData);
else if (StrValid(Namespace)) RetStr=MCatStr(RetStr, "<",Namespace,":",TagType," ",TagData,">",NULL);
else if (StrValid(TagType)) RetStr=MCatStr(RetStr, "<",TagType," ",TagData,">",NULL);
else RetStr=MCatStr(RetStr, TagData);
ptr=XMLGetTag(ptr, &Namespace, &TagType, &TagData);
}
DestroyString(Namespace);
DestroyString(TagType);
DestroyString(TagData);
return(RetStr);
}