C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$RAQKNYH\admin\sessioncontrol.php


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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.

* $Id: sessioncontrol.php 6606 2009-04-09 18:26:36Z c_schmitz $
*/

// Security Checked: POST, GET, SESSION, REQUEST, returnglobal, DB     

//SESSIONCONTROL.PHP FILE MANAGES ADMIN SESSIONS. 
//Ensure script is not run directly, avoid path disclosure

if (!isset($dbprefix) || isset($_REQUEST['dbprefix'])) {die("Cannot run this script directly");}

// Read the session name from the settings table
$usquery "SELECT stg_value FROM ".db_table_name("settings_global")." where stg_name='SessionName'";
$usresult db_execute_assoc($usquery,'',true);       // CHecked
if ($usresult)
{
    
$usrow $usresult->FetchRow();
    @
session_name($usrow['stg_value']);
}
 else {
session_name("LimeSurveyAdmin");}
 
 
if (
session_id() == ""
{
   if (
$debug==0) {@session_start();}
    else  {
session_start();}
}
//LANGUAGE ISSUES
// if changelang is called from the login page, then there is no userId 
//  ==> thus we just change the login form lang: no user profile update
// if changelang is called from another form (after login) then update user lang
// when a loginlang is specified at login time, the user profile is updated in usercontrol.php 
if (returnglobal('action') == "changelang" && (!isset($login) || !$login ))    
    {
    
$_SESSION['adminlang']=returnglobal('lang');
    
// if user is logged in update language in database
    
if(isset($_SESSION['loginID']))
        {
        
$uquery "UPDATE {$dbprefix}users SET lang='{$_SESSION['adminlang']}' WHERE uid={$_SESSION['loginID']}";    //        added by Dennis
        
$uresult $connect->Execute($uquery); //Checked
        
}
    }
elseif (!isset(
$_SESSION['adminlang']) || $_SESSION['adminlang']=='' )
    {
    
$_SESSION['adminlang']=$defaultlang;
    }

// if changehtmleditormode is called then update user htmleditormode
if (returnglobal('action') == "changehtmleditormode" )    
    {
    
$_SESSION['htmleditormode']=returnglobal('htmleditormode');
    if(isset(
$_SESSION['loginID']))
        {
        
$uquery "UPDATE {$dbprefix}users SET htmleditormode='{$_SESSION['htmleditormode']}' WHERE uid={$_SESSION['loginID']}";    //        added by Dennis
        
$uresult $connect->Execute($uquery) or die("Can't update htmleditor setting"); //Checked
        
}
    }
elseif (!isset(
$_SESSION['htmleditormode']) || $_SESSION['htmleditormode']=='' )
    {
    
$_SESSION['htmleditormode']=$defaulthtmleditormode;
    }

// Construct the language class, and set the language.
if (isset($_REQUEST['rootdir'])) {die('You cannot start this script directly');}
require_once(
$rootdir.'/classes/core/language.php');
$clang = new limesurvey_lang($_SESSION['adminlang']);

// get user rights
if(isset($_SESSION['loginID'])) {GetSessionUserRights($_SESSION['loginID']);}
    
// check that requests that modify the DB are using POST
// and not GET requests
$dangerousActionsArray = Array
    (
        
'changelang' => Array(),
        
'changehtmleditormode' => Array(),
        
'deluser' => Array(),
        
'moduser' => Array(),
        
'usertemplates' => Array(),
        
'adduser' => Array(),
        
'usergroupindb' => Array(),
        
'editusergroupindb' => Array(),
        
'deleteuserfromgroup' => Array(),
        
'addusertogroup' => Array(),
        
'delusergroup' => Array(),
        
'mailsendusergroup' => Array(),
        
'insertnewsurvey' => Array(),
        
'importsurvey' => Array(),
        
'updatesurvey' => Array(),
        
'importsurvresources' => Array(),
        
'updatesurvey2' => Array(),
        
'deletesurvey' => Array(),
        
'renumberquestions' => Array(),
        
'insertnewgroup' => Array(),
        
'importgroup' => Array(),
        
'updategroup' => Array(),
        
'delgroup' => Array(),
        
'insertnewquestion' => Array(),
        
'importquestion' => Array(),
        
'updatequestion' => Array(),
        
'copynewquestion' => Array(),
        
'delquestion' => Array(),
        
'addattribute' => Array(),
        
'editattribute' => Array(),
        
'delattribute' => Array(),
        
'modanswer' => Array(),
        
'resetsurveylogic' => Array(),
        
'activate' => Array(
                
=> Array ('ok' => 'Y')
                ),
        
'deactivate' => Array(
                
=> Array('ok' => 'Y')
                ),
        
'conditions' => Array(
            
=> Array('subaction' => 'insertcondition'),
            
=> Array('subaction' => 'delete'),
            
=> Array('subaction' => 'copyconditions'),
            
=> Array('subaction' => 'updatecondition'),
            
=> Array('subaction' => 'deletescenario'),
            
=> Array('subaction' => 'updatescenario'),
            
=> Array('subaction' => 'deleteallconditions'),
            
=> Array('subaction' => 'renumberscenarios')
            ),
        
'insertlabelset' => Array(),
        
'importlabels' => Array(),
        
'modlabelsetanswers' => Array(),
        
'importlabelresources' => Array(),
        
'deletelabelset' => Array(),
        
'templatecopy' => Array(),
        
'templaterename' => Array(),
        
'assessmentadd' => Array(),
        
'assessmentedit' => Array(),
        
'assessmentdelete' => Array(),
        
'iteratesurvey' => Array(
            
=> Array('subaction' => 'unfinalizeanswers')
            ),
        
'dataentry' => Array(
            
=> Array('subaction' => 'delete'),
            
=> Array('subaction' => 'update'),
            
=> Array('subaction' => 'insert'),
            ),
        
'tokens' => Array(
            
=> Array('subaction' => 'updatetoken'),
            
=> Array('subaction' => 'inserttoken'),
            
=> Array('subaction' => 'upload'),
            
=> Array('subaction' => 'uploadldap'),
            
=> Array('subaction' => 'updateemailsettings'),
            
=> Array('subaction' => 'email''ok' => 'absolutely'),
            
=> Array('subaction' => 'remind''ok' => 'absolutely'),
            
=> Array('subaction' => 'tokenify'),
            
=> Array('subaction' => 'kill'),
            
=> Array('subaction' => 'delete'),
            
10 => Array('subaction' => 'clearinvites'),
            
11 => Array('subaction' => 'cleartokens'),
            
12 => Array('subaction' => 'deleteall'),
            
13 => Array('createtable' => 'Y')
            ),
        
'quotas' => Array(
            
=> Array('subaction' => 'new_quota'),
            
=> Array('subaction' => 'insertquota'),
            
=> Array('subaction' => 'quota_delquota'),
            
=> Array('subaction' => 'modifyquota'),
            
=> Array('subaction' => 'new_answer_two'),
            
=> Array('subaction' => 'new_answer'),
            
=> Array('subaction' => 'insertquotaanswer'),
            
=> Array('subaction' => 'quota_delans')
            )
    );

if (
$_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['action']) && 
    isset(
$dangerousActionsArray[$_GET['action']]))
{
    
$getauthorized=true;
    if (
is_array($dangerousActionsArray[$_GET['action']]))
    {
        foreach (
$dangerousActionsArray[$_GET['action']] as $key => $arrayparams)
        {
            
$totalparamcount=count($arrayparams);
            
$matchparamcount=0;
            foreach (
$arrayparams as $param => $val)
            {
                if (isset(
$_GET[$param]) &&
                    
$_GET[$param] == $val)
                {
                    
$matchparamcount++;
                }
            }
            if (
$matchparamcount == $totalparamcount)
            {
                
$getauthorized=false;
                break;
            }
        }
    }
    else
    { 
// ERROR
        
$getauthorized=false;
    }

    if (
$getauthorized === false)
    {
        
$_GET['action'] = 'FakeGET';
        
$action 'FakeGET';
        
$_REQUEST['action'] = 'FakeGET';
        if (isset(
$_GET['subaction'])) {unset($_GET['subaction']);}
        if (isset(
$_REQUEST['subaction'])) {unset($_REQUEST['subaction']);}
    }
}

if (
$_SERVER['REQUEST_METHOD'] == 'POST' && 
    
returnglobal('action') != 'login' &&
    
returnglobal('action') != 'forgotpass' &&
    
returnglobal('action') != 'changelang' &&
    
returnglobal('action') != '')
{
    if (
returnglobal('checksessionbypost') != $_SESSION['checksessionpost'])
    {
        
error_log("LimeSurvey ERROR while checking POST session- Probable CSRF attack Received=".returnglobal('checksessionbypost')." / Expected= ".$_SESSION['checksessionpost']." for action=".returnglobal('action')." .");
        
$subaction='';
        if (isset(
$_POST['action'])) {unset($_POST['action']);}
        if (isset(
$_REQUEST['action'])) {unset($_REQUEST['action']);}
        if (isset(
$_POST['subaction'])) {unset($_POST['subaction']);}
        if (isset(
$_REQUEST['subaction'])) {unset($_REQUEST['subaction']);}
        
$_POST['action'] = 'CSRFwarn';
        
$_REQUEST['action'] = 'CSRFwarn';
        
$action='CSRFwarn';
        
//include("access_denied.php");
    
}
}

function 
GetSessionUserRights($loginID)
{
    global 
$dbprefix,$connect
    
$squery "SELECT create_survey, configurator, create_user, delete_user, superadmin, manage_template, manage_label FROM {$dbprefix}users WHERE uid=$loginID";
    
$sresult db_execute_assoc($squery); //Checked
    
if ($sresult->RecordCount()>0)
        {
        
$fields $sresult->FetchRow();
        
$_SESSION['USER_RIGHT_CREATE_SURVEY'] = $fields['create_survey'];
        
$_SESSION['USER_RIGHT_CONFIGURATOR'] = $fields['configurator'];
        
$_SESSION['USER_RIGHT_CREATE_USER'] = $fields['create_user'];
        
$_SESSION['USER_RIGHT_DELETE_USER'] = $fields['delete_user'];
        
$_SESSION['USER_RIGHT_SUPERADMIN'] = $fields['superadmin'];
        
$_SESSION['USER_RIGHT_MANAGE_TEMPLATE'] = $fields['manage_template'];
        
$_SESSION['USER_RIGHT_MANAGE_LABEL'] = $fields['manage_label'];
        }



    
// SuperAdmins
    // * original superadmin with uid=1 unless manually changed and defined
    //   in config-defaults.php
    // * or any user having USER_RIGHT_SUPERADMIN right

    // Let's check if I am the Initial SuperAdmin
    
$adminquery "SELECT uid FROM {$dbprefix}users WHERE parent_id=0";
    
$adminresult db_select_limit_assoc($adminquery1);
    
$row=$adminresult->FetchRow();
    if(
$row['uid'] == $_SESSION['loginID'])
    {
        
$initialSuperadmin=true;
    }
    else
    {
        
$initialSuperadmin=false;
    }

    if ( 
$initialSuperadmin === true)
    {
        
$_SESSION['USER_RIGHT_SUPERADMIN'] = 1;
        
$_SESSION['USER_RIGHT_INITIALSUPERADMIN'] = 1;
    }
    else
    {
        
$_SESSION['USER_RIGHT_INITIALSUPERADMIN'] = 0;
    }
}


    
?>